what is error suppressor in php

王林
Release: 2023-03-03 22:24:01
Original
3349 people have browsed it

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.

?>
Copy after login

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!