Home >Backend Development >PHP Tutorial >php error control operator
PHP supports an error control operator: @. When placed before a PHP expression, any error message that expression may produce is ignored.
If you set a custom error handling function with set_error_handler(), it will still be called, but this error handling function can (and should) call error_reporting(), and this function will return when there is @ before the error statement 0.
If the track_errors feature is activated, any error messages generated by the expression are stored in the variable $php_errormsg. This variable is overwritten on every error, so check it as early as possible if you want to use it.
<?php /* Intentional file error */ $my_file = @file ('non_existent_file') or die ("Failed opening file: error was '$php_errormsg'"); // 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 is only valid for expressions. A simple rule for beginners is: if you can get a value from somewhere, prepend it with the @ operator. For example, you can put it before variables, function and include calls, constants, etc. It cannot be placed before the definition of a function or class, nor can it be used in conditional structures such as if and foreach.
Warning
[email protected]��[email protected]�[email protected]�� to suppress the error message, the script will die there without any indication of the reason.