PHP 中的 @ 符号有什么用?
phpserver side programmingprogramming更新于 2025/10/9 6:52:17
PHP 支持错误控制运算符,即 @ 符号。当 @ 添加到表达式之前时,该表达式可能生成的任何错误消息都将被忽略。
要在 PHP 中使用 @ 符号,代码如下: −
示例
<?php
$file = @file ('non_existent_file') or
die ("Failed in opening the file: Error Message = '$err'");
$value = @$cache[$key];
?>
输出
这将产生以下输出−
Failed in opening the file: Error Message = ''PHP Notice: Undefined variable: err in /home/cg/root/6985034/main.php on line 4
示例
Let us now see another example−
<?php $val = $test['5'] $val = @$test['5'] ?>
输出
这将产生以下输出−
PHP Parse error: syntax error, unexpected '$val' (T_VARIABLE) in /home/cg/root/6985034/main.php on line 5

