#39;At#39; symbol before variable name in PHP: @$_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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP中变量名前的'At'符号:@$_POST


基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01