I've seen function calls preceded with an at symbol to switch off warnings. Today I was skimming some code and found this:
$hn = @$_POST['hn'];
What good will it do here?
I've seen function calls preceded with an at symbol to switch off warnings. Today I was skimming some code and found this:
$hn = @$_POST['hn'];
What good will it do here?
It suppresses warnings if $_POST['something'] is not defined.
Something that others forgot to mention is that besides ignoring the NOTICE, the variable will be set to
NULL
.It won't throw a warning if $_POST['hn'] is not set.
The
@
is the error suppression operator in PHP.See:
Update:
In your example, it is used before the variable name to avoid the
E_NOTICE
error there. If in the$_POST
array, thehn
key is not set; it will throw anE_NOTICE
message, but@
is used there to avoid thatE_NOTICE
.Note that you can also put this line on top of your script to avoid an
E_NOTICE
error:All that means is that, if $_POST['hn'] is not defined, then instead of throwing an error or warning, PHP will just assign NULL to $hn.