PHP: suppress error with operator @
May 03, 2011 09:42:12 Last update: May 03, 2011 09:42:12
The @ operator suppresses error messages.
A usual example is:
which suppresses the "undefined index" PHP notice.
Another example is:
In this case,
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.
- Create file
test.php:<?php @include('test.inc'); ?>
- Create
test.inc:<?php <?php garbage ?>
- The "undefined constant" PHP notice message is suppressed by
@.