views:

138

answers:

4

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?

Edit: corrected my mistake in naming the symbol. Thanks for pointing it.

+6  A: 
Sarfraz
But it is used before a variable name not a function.
Majid
@Majid: See my update please.
Sarfraz
if `hn` is not set in $_POST, it will throw a notice (`Notice: undefined index...`). `@` will suppress that notice. But using `@` is just wrong.
robertbasic
Understand now. Thank you Sarfaraz. Hope your people could put the flood behind them soon.
Majid
@Majid: Welcome :)
Sarfraz
"PHP6 Note" —— that makes **no** sense.
salathe
+3  A: 

It won't throw a warning if $_POST['hn'] is not set.

Tyson of the Northwest
+1 Brief and to the point. Thanks!
Majid
+1  A: 

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.

SenorPuerco
+1 Thank you. Good answer.
Majid
+1  A: 

It suppress warning if $_POST['something'] is not defined.

aromawebdesign.com