Home  >  Article  >  Backend Development  >  php error control operator

php error control operator

伊谢尔伦
伊谢尔伦Original
2016-11-24 13:29:151674browse

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 (&#39;non_existent_file&#39;) or
    die ("Failed opening file: error was &#39;$php_errormsg&#39;");
// this works for any expression, not just functions:
$value = @$cache[$key];
// will not issue a notice if the index $key doesn&#39;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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php execution operatorNext article:php execution operator