isset($var) vs. @$var

前端 未结 5 1131
逝去的感伤
逝去的感伤 2020-12-11 02:18

Is this an okay practice or an acceptable way to use PHP\'s error suppressing?

if (isset($_REQUEST[\'id\']) && $_REQUEST[\'id\'] == 6) {
  echo \'hi\         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-11 02:45

    No, it's not really an acceptable practice in my opinion. Apart from the fact that it looks sloppy, custom error handlers are still triggered even when using error suppression.

    The manual offers more reasons to avoid its use altogether:

    Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.

提交回复
热议问题