isset($var) 与 @$var
这是使用 PHP 错误抑制的好做法还是可接受的方法?
Is this an okay practice or an acceptable way to use PHP's error suppressing?
if (isset($_REQUEST['id']) && $_REQUEST['id'] == 6) {
echo 'hi';
}
if (@$_REQUEST['id'] == 6) {
echo 'hi';
}
我也是这么想的.代码(和想法)来自朋友.
谢谢你证明我是对的.:)
I thought so too. The code (and idea) is from friend.
Thanks for proving me right. :)
推荐答案
使用错误抑制并不是一个很好的做法.使用 $_REQUEST 甚至都不是一个好习惯.只需使用 isset() 或 !empty() 或其他什么,不要偷懒.
It's not a really good practice to use error suppressing. It's even not a good practice to use $_REQUEST at all. Just use isset() or !empty() or whatever, don't be lazy.
还有一件事,在使用isset()时关闭括号是一个好习惯":)
And one more thing, it is a "good practice" to close parenthesis when using isset() :)
相关文章