December 27th, 2012, 11:55 AM
I have to change the php code which someone wrote before.
There is one thing I dont understand.
There are so many @$_post in her/his codes which I've never seen before.
Could anyone tell me the difference between,
@$_post and $_post ?
December 27th, 2012, 12:14 PM
this "@" is the poor man's version of error handling. It simply suppresses any error from the following expression.
The "@" is bad practice, escpecially when used excessively. So you can thank your predecessor for leaving you sh*tty code and start repairing it (unless it doesn't matter, anyway).
December 27th, 2012, 06:15 PM
You're probably seeing it in something like the following:
The appropriate way to do that is:
$var = @$_POST['var'];
If you did it the first way without the @, then an E_NOTICE would be thrown if a value named 'var' were not submitted with the POST request. However, handling that error by suppressing it is bad practice as already mentioned.
$var = isset($_POST['var']) ? $_POST['var'] : '';