Error Control Operators

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any diagnostic error that might be generated by that expression will be suppressed.

If a custom error handler function is set with set_error_handler(), it will still be called even though the diagnostic has been suppressed, as such the custom error handler should call error_reporting() and verify that the @ operator was used in the following way:

function my_error_handler($err_no$err_msg$filename$linenum) {
    if (!(
error_reporting() & $err_no)) {
false// Silenced
// ...


Prior to PHP 8.0.0, the value of the severity passed to the custom error handler was always 0 if the diagnostic was suppressed. This is no longer the case as of PHP 8.0.0.

Any error message generated by the expression is available in the "message" element of the array returned by error_get_last(). The result of that function will change on each error, so it needs to be checked early.

/* Intentional file error */
$my_file = @file ('non_existent_file') or
    die (
"Failed opening file: error was '" error_get_last()['message'] . "'");

// this works for any expression, not just functions:
$value = @$cache[$key];
// will not issue a notice if the index $key doesn't exist.


Note: The @-operator works only on expressions. A simple rule of thumb is: if one can take the value of something, then one can prepend the @ operator to it. For instance, it can be prepended to variables, functions calls, certain language construct calls (e.g. include), and so forth. It cannot be prepended to function or class definitions, or conditional structures such as if and foreach, and so forth.


Prior to PHP 8.0.0, it was possible for the @ operator to disable critical errors that will terminate script execution. For example, prepending @ to a call of a function which did not exist, by being unavailable or mistyped, would cause the script to terminate with no indication as to why.