您好,欢迎访问一九零五行业门户网

PHP中的@符号有什么用

at符号(@)在php中用作错误控制操作符。当表达式附加@符号时,将忽略该表达式可能生成的错误消息。如果启用了track_errors功能,则表达式生成的错误消息将保存在变量$ php_errormsg中。每个错误都会覆盖此变量。
推荐手册:php完全自学手册
示例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.
注意:使用@是非常糟糕的编程习惯,因为它不会使错误消失,它只是隐藏它们,并且它使调试变得更糟,因为我们无法看到我们的代码实际上有什么问题。
相关文章推荐:
1.php中的异常和错误解析
2.php错误控制运算符@ or die()实例用法详解
相关视频推荐:
1.独孤九贱(4)_php视频教程
以上就是php中的@符号有什么用的详细内容。
其它类似信息

推荐信息