問(wèn)題描述
我見(jiàn)過(guò)以 at 符號(hào)開(kāi)頭的函數(shù)調(diào)用來(lái)關(guān)閉警告.今天我瀏覽了一些代碼,發(fā)現(xiàn)了這個(gè):
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 中的錯(cuò)誤抑制運(yùn)算符.
The @
is the error suppression operator in PHP.
PHP 支持一種錯(cuò)誤控制運(yùn)算符:at 符號(hào) (@).什么時(shí)候附加到 PHP 中的表達(dá)式,任何可能產(chǎn)生的錯(cuò)誤信息由該表達(dá)式將被忽略.
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.
見(jiàn):
- 錯(cuò)誤控制運(yùn)算符
- @ 運(yùn)算符的不當(dāng)使用
在您的示例中,它用在變量名之前,以避免出現(xiàn) E_NOTICE
錯(cuò)誤.如果在$_POST
數(shù)組中,沒(méi)有設(shè)置hn
鍵;它會(huì)拋出一個(gè) 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
.
請(qǐng)注意,您也可以將此行放在腳本頂部以避免E_NOTICE
錯(cuò)誤:
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);
這篇關(guān)于PHP中變量名前的'At'符號(hào):@$_POST的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!