Reputation: 4607
I see some code that looks like this:
if(@$_POST['myvar'])
What does the @ sign do in this instance?
Upvotes: 1
Views: 199
Reputation: 48897
It suppresses any warnings/notices/errors from being printed. For instance, if $_POST['myvar']
we're undefined, PHP may output an Undefined index
notice. The @
prevents that behavior.
That being said, it is considered bad practice to arbitrarily suppress warnings. You can, instead, check for the variable being set with if (isset($_POST['myvar']) && $_POST['myvar'])
http://www.php.net/manual/en/language.operators.errorcontrol.php
Upvotes: 6
Reputation: 22340
It suppresses any and all error messages, warnings, or notifications caused by the expression you've prepended it to. In this case: if(@$_POST['myvar'])
it is probably being used because the original author did not want a notification to be emitted if $_POST['myvar']
is unset.
Upvotes: 4