I see some code th开发者_如何学编程at looks like this:
if(@$_POST['myvar'])
What does the @ sign do in this instance?
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
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.
精彩评论