The error suppressor in php is @, and the @ operator is only valid for expressions. When we place it before a PHP expression, any error messages that may be generated by the expression will be ignored, using methods such as: [$value = @$cache[$key];].
#PHP supports an error control operator: @. When placed before a PHP expression, any error message that expression may produce is ignored.
(Recommended tutorial: php graphic tutorial)
If you use set_error_handler() to set a custom error handling function, it will still be called, but this error The handler function can (and should) call error_reporting(), which will return 0 if there is @ before the error statement.
Example:
<?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. ?>
@ Operator is only valid for expressions.
(Video tutorial recommendation: Introduction to Programming)
A simple rule for novices is: if you can get a value from somewhere, you can add it in front of it on 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.
The above is the detailed content of what is error suppressor in php. For more information, please follow other related articles on the PHP Chinese website!