Home > Backend Development > PHP Tutorial > php error control operator

php error control operator

伊谢尔伦
Release: 2016-11-24 13:29:15
Original
1687 people have browsed it

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.
?>
Copy after login

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.


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template