Posts Tagged ‘php-syntax’

Cool PHP error-suppressing operator – the @ operator

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


With @, this isset(…) stuff is no longer needed



= array(‘a’=>1, ‘bb’=>22);

echo ‘<h2>error</h2>’;
$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!