at符号(@)在PHP中用作错误控制操作符。当表达式附加@符号时,将忽略该表达式可能生成的错误消息。如果启用了track_errors功能,则表达式生成的错误消息将保存在变量$ php_errormsg中。每个错误都会覆盖此变量。
示例1<?php
// 文件错误
$file_name = @file ('non_existent_file') or
die ("Failed in opening the file: error: '$errormsg'");
// 它用于表达
$value = @$cache[$key];
//如果索引$key不存在,它将不显示通知。
?>
运行时错误:PHP Notice: Undefined variable: errormsg in /home/fe74424b34d1adf15aa38a0746a79bed.php on line 5
输出:Failed in opening the file: error: ''
示例2<?php
// 语句1
$result= $hello['123']
// 语句2
$result= @$hello['123']
?>
它将仅执行语句1并显示通知消息PHP Notice: Undefined variable: hello.
注意:使用@是非常糟糕的编程习惯,因为它不会使错误消失,它只是隐藏它们,并且它使调试变得更糟,因为我们无法看到我们的代码实际上有什么问题。