Home  >  Article  >  Backend Development  >  what is error suppressor in php

what is error suppressor in php

王林
王林Original
2020-08-06 14:20:373389browse

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];].

what is error suppressor in php

#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 (&#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.

?>

@ 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!

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

Related articles

See more