PHP中的变量名之前的'At'符号:@ $ _ POST [英] 'At' symbol before variable name in PHP: @$_POST
问题描述
我已经看到函数调用前面带有一个符号来关闭警告。今天我撇了一些代码,发现这一点:
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.
请参阅
- Error Control Operators
- Bad uses of the @ operator
在你的例子中 以避免 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!