Reputation:
What does adding @ before a function do? I've seen this in some scripts
example:
$connect = @mysql_connect('localhost', 'root', 'password');
instead of
$connect = mysql_connect('localhost', 'root', 'password');
Upvotes: 3
Views: 181
Reputation: 12574
this is the Error Control Operator, from php documentation:
PHP supports one error control operator: the at sign (
@
). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.If you have set a custom error handler function with
set_error_handler()
then it will still get called, but this custom error handler can (and should) callerror_reporting()
which will return 0 when the call that triggered the error was preceded by an@
.If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable
$php_errormsg
. This variable will be overwritten on each error, so check early if you want to use it.
Upvotes: 0
Reputation: 488414
It suppresses any errors that might happen inside the function. Documentation here.
All things considered, this is not recommended as it can lead to some sneaky bugs.
Upvotes: 12