There are some good use cases for using @
in PHP.
One great example is if you're writing object oriented code and you want a clean object api that throws exceptions when something goes wrong. You're designing your class, and your object performs, say, a file_get_contents
call in there. In order to maintain a nice, self-contained object api, you'll want to throw an exception when something goes wrong.
@file_get_contents(...)
Prefixing the @
there allows you suppress the warning and ensure that the user of this object gets an exception. Instead, check for a false
then throw your exception.
Why do you have to do this? Because php is a daft mix of functions that have no similarities or standards when compared with each other.
And with your specific example, which is nothing to do with @
, you'd do an isset($_SESSION['login'])
.