isset($var) 与 @$var [英] isset($var) vs. @$var

查看:24
本文介绍了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() :)

这篇关于isset($var) 与 @$var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆