What is the use of @ symbol in PHP

藏色散人
Release: 2023-04-04 20:26:02
Original
36295 people have browsed it

The at symbol (@) is used as an error control operator in PHP. When an expression is appended with the @ symbol, error messages that may be generated by the expression are ignored. If the track_errors feature is enabled, the error message generated by the expression will be saved in the variable $php_errormsg. This variable is overwritten with every error.

What is the use of @ symbol in PHP

Recommended manual: php complete self-study manual

Example 1

<?php 
  
// 文件错误 
$file_name = @file (&#39;non_existent_file&#39;) or
    die ("Failed in opening the file: error: &#39;$errormsg&#39;"); 
  
// 它用于表达
$value = @$cache[$key]; 
  
//如果索引$key不存在,它将不显示通知。 
  
?>
Copy after login

Runtime Error:

PHP Notice:  Undefined variable: errormsg in /home/fe74424b34d1adf15aa38a0746a79bed.php on line 5
Copy after login

Output:

Failed in opening the file: error: &#39;&#39;
Copy after login

Example 2

<?php 
  
// 语句1
$result= $hello[&#39;123&#39;] 
  
// 语句2
$result= @$hello[&#39;123&#39;] 
?>
Copy after login

It will only execute Statement 1 and displays the notification message

PHP Notice:  Undefined variable: hello.
Copy after login

NOTE: Using @ is a very bad programming practice because it doesn't make the errors go away, it just hides them, and it makes debugging harder It sucks because we can't see what's actually wrong with our code.

Related article recommendations:
1.Exception and error analysis in php
2.php error control operator @ or die () Detailed explanation of usage examples
Related video recommendations:
1. Dugu Jiujian (4)_PHP video tutorial

The above is the detailed content of What is the use of @ symbol in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!