gpt4 book ai didi

php - PHP : @$_POST 中变量名前的“At”符号

转载 作者:IT王子 更新时间:2023-10-28 23:55:43 26 4
gpt4 key购买 nike

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

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

它在这里有什么用?

最佳答案

@ 是 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

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

error_reporting(E_ALL ^ E_NOTICE);

关于php - PHP : @$_POST 中变量名前的“At”符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3551527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com