Today by accident I get new php syntax – the @ operator
I often see code
if ( isset($REQUEST['someName'] && … ) {
…
}
The `…` in the if statement is the real/futher expression usage on
isset($REQUEST['someName']
With @, this isset(…) stuff is no longer needed
e.g. $a = array(‘a’=>1, ‘bb’=>22);
<?php
$b = $a['ccc']==333 ? 1 : 2;
echo $b;
echo ‘<h1>no-error</h1>’;
$b = @$a['ccc']==333 ? 1 : 2;
echo $b;
To me, the @ operator saves & eases myself from worrying if a field in the `$_REQUEST`/array already exists or not. With @, I just call it out and write the expression/condition for it without bothering to start with isset(…) any longer!
Hope you would share this cool operator with me!
Nam
ref.
http://www.php.net/manual/en/language.operators.errorcontrol.php
Posted by N.B. on February 25, 2012 at 5:14 PM
Quote: “With @, this isset(…) stuff is no longer needed”
Wrong. The “@” is there to “silence” PHP. The actual error will still go to the error log. You are proposing a terribly bad practice of abandoning isset() function for using silencing operator. That’s so terribly bad that I can’t believe you think it’s a good thing. Just don’t do it, and if you do – don’t blog about it. It’s very, very, very bad thing to do if you are a PHP programmer and use @ instead of isset().
Posted by Nam Gi VU on March 23, 2012 at 10:22 PM
Please read to the end my friend. Thank you for you straight comment. I’m not a fool PHP coder though.
Quote “To me, the @ operator saves & eases myself from worrying if a field in the `$_REQUEST`/array already exists or not. With @, I just call it out and write the expression/condition for it without bothering to start with isset(…) any longer!”