可能没有其他人指出的功能差异,但使用if(@ $x)似乎不正确并且有理由不使用它.
从关于suppression error operator的文档:
If you have set a custom error handler function with set_error_handler() then it will still get called,but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @.
在同一页的一条评论中有人写道:
I was confused as to what the @ symbol actually does,and after a few experiments have concluded the following:
-
the error handler that is set gets called regardless of what level the error reporting is set on,or whether the statement is preceeded
with @
-
it is up to the error handler to impart some meaning on the different error levels. You could make your custom error handler echo
all errors,even if error reporting is set to NONE.
-
so what does the @ operator do? It temporarily sets the error reporting level to 0 for that line. If that line triggers an error,
the error handler will still be called,but it will be called with an
error level of 0
Hope this helps someone
简而言之,如果您使用if(@ $x)而不是isset和empty,您可能看不到任何差异,但幕后有一些额外的工作.这是因为即使您禁止错误,也会始终调用错误处理程序.