What is the error control operator in php

青灯夜游
Release: 2023-03-13 08:06:01
Original
2264 people have browsed it

The error control operator in php is "@". If you place it before a PHP expression, any error information that may be generated by the expression will be ignored. The "@" operator is only valid for expressions. It can be placed before variables, functions, include calls, constants, etc., but cannot be placed before the definition of a function or class.

What is the error control operator in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php error control operation Symbol: @

#PHP supports the use of the error control operator @. Place it before a PHP expression and any error messages the expression may produce will be ignored.

If a custom error handling function is set with set_error_handler(), this error handling function will still be called, and if @ is used before the error statement, the error handling function will return 0.

It should be noted that the @ operator is only valid for expressions. Simply put, if you can get a value from somewhere, you can add the @ operator in front of it. For example, the @ operator can be used before variables, functions, include calls, constants, etc., but it cannot be placed before the definition of a function or class, nor can it be used before conditional structures such as if and foreach statements. The

@ operator is also effective for serious errors that can cause the program to terminate. This means that if @ is used to suppress the error message before a function call that does not exist or has the wrong letter, the program will Die there without any hint.

[Example] Use the @ error control operator to mask errors in the code.

<?php
    $link = @mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db") or die(&#39;数据库连接失败!&#39;);
?>
Copy after login

The running results are as follows:

数据库连接失败!
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the error control operator 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!