PHP: suppress error with operator @ 

Joined:
03/10/2011
Posts:
84

May 03, 2011 09:42:12    Last update: May 03, 2011 09:42:12
The @ operator suppresses error messages.

A usual example is:
<?php
$v = @$a['non-existing-key'];
?>

which suppresses the "undefined index" PHP notice.

Another example is:
<?php
@include('non_existent_file');
?>


In this case, @ not only suppresses error messages for non-existing file, it also suppresses any error messages coming from the included file when it does exist.
  1. Create file test.php:
    <?php
    @include('test.inc');
    ?>
    

  2. Create test.inc:
    <?php
    <?php
        garbage
    ?>
    

  3. The "undefined constant" PHP notice message is suppressed by @.
Share |
| Comment  | Tags