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.
Recommended manual: php complete self-study manual
Example 1
<?php // 文件错误 $file_name = @file ('non_existent_file') or die ("Failed in opening the file: error: '$errormsg'"); // 它用于表达 $value = @$cache[$key]; //如果索引$key不存在,它将不显示通知。 ?>
Runtime Error:
PHP Notice: Undefined variable: errormsg in /home/fe74424b34d1adf15aa38a0746a79bed.php on line 5
Output:
Failed in opening the file: error: ''
Example 2
<?php // 语句1 $result= $hello['123'] // 语句2 $result= @$hello['123'] ?>
It will only execute Statement 1 and displays the notification message
PHP Notice: Undefined variable: hello.
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!