PHP中变量名前的'At'符号:@$_POST

#39;At#39; symbol before variable name in PHP: @$_POST(PHP中变量名前的At符号:@$_POST)
本文介绍了PHP中变量名前的'At'符号:@$_POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我见过以 at 符号开头的函数调用来关闭警告.今天我浏览了一些代码,发现了这个:

I've seen function calls preceded with an at symbol to switch off warnings. Today I was skimming some code and found this:

$hn = @$_POST['hn'];

它在这里有什么好处?

推荐答案

@ 是 PHP 中的错误抑制运算符.

The @ is the error suppression operator in PHP.

PHP 支持一种错误控制运算符:at 符号 (@).什么时候附加到 PHP 中的表达式,任何可能产生的错误信息由该表达式将被忽略.

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

见:

  • 错误控制运算符
  • @ 运算符的不当使用

在您的示例中,它用在变量名之前,以避免出现 E_NOTICE 错误.如果在$_POST数组中,没有设置hn键;它会抛出一个 E_NOTICE 消息,但 @ 用于避免 E_NOTICE.

In your example, it is used before the variable name to avoid the E_NOTICE error there. If in the $_POST array, the hn key is not set; it will throw an E_NOTICE message, but @ is used there to avoid that E_NOTICE.

请注意,您也可以将此行放在脚本顶部以避免E_NOTICE 错误:

Note that you can also put this line on top of your script to avoid an E_NOTICE error:

error_reporting(E_ALL ^ E_NOTICE);

这篇关于PHP中变量名前的'At'符号:@$_POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Why can#39;t I update data in an array with foreach loop?(为什么我不能用 foreach 循环更新数组中的数据?)
Foreach for arrays inside of an array(Foreach 用于数组内的数组)
PHP array get next key/value in foreach()(PHP 数组在 foreach() 中获取下一个键/值)
Using preg_match on a multidimensional array to return key values arrays(在多维数组上使用 preg_match 返回键值数组)
php foreach as key, every two number as a group(php foreach 为key,每两个数字为一组)
Treat a PHP class that implements Iterator as an array(将实现 Iterator 的 PHP 类视为数组)