Skip to content
Tutorials Center
My learning

Topics

PHP Reference ยท Operators

The PHP @ error control operator

Reference for the PHP @ operator: how it silences diagnostics, what it no longer hides in PHP 8, its performance cost and better alternatives.

The @ operator placed in front of an expression silences the warnings, notices and deprecations that expression would produce. Execution continues as usual and you get whatever value the expression returns, often false or null.

It hides information instead of handling it. Use it almost never: check the condition up front, use a function that reports failure cleanly, or catch an exception. If an error is genuinely expected and cannot be tested for, @ with an explicit check of the result is acceptable.

PHP
$text = @file_get_contents("maybe-missing.txt");
if ($text === false) { /* handle it */ }

Try it

PHP Silencing a warning

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

PHP What @ does not hide

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

PHP Check first instead

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Syntax

PHP
@expression

Result: the value of the expression. The last silenced diagnostic is still available from error_get_last().

Usage notes

  • Fatal errors and exceptions are not suppressed. @intdiv(1, 0) still throws DivisionByZeroError. In PHP 8 @ also no longer hides fatal errors.
  • Custom error handlers still run. A handler set with set_error_handler() is called even for silenced errors; inside it, check error_reporting() & $errno before reacting. Since PHP 8 error_reporting() returns a reduced mask (4437) while @ is active.
  • It costs time. @ temporarily changes error_reporting, so avoid it in hot loops.
  • It hides real bugs. An undefined variable or index quietly produces null, and the typo stays unnoticed. Use isset(), ?? or array_key_exists().
  • Better alternatives: ?? for missing keys, is_readable() or file_exists() before file functions, JSON_THROW_ON_ERROR for JSON, filter_var() for validation, and try/catch for exceptions.
  • It binds tightly. @$a + $b silences only $a. Put it directly in front of the call you want quiet.
  • Never use it to hide errors in production. Configure logging (log_errors) and turn display_errors off instead.