有一些原因使用PHP错误控制操作符@是坏的:
1-从PHP手册
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.
2-如果您使用@,您仍可能使用不推荐使用的函数:
if(eregi("a", "abc")) echo "a";产生此错误:
Deprecated: Function eregi() is deprecated in D:\htdocs\test.php on line 2使用if(@eregi("a", "abc")) echo "a";时不会发出任何消息。
3-其他事实:
http://us3.php.net/manual/en/language.operators.errorcontrol.php#99805
Be aware that using @ is dog-slow, as PHP incurs overhead to
suppressing errors in this way. It's a trade-off between speed and
convenience.
http://us3.php.net/manual/en/language.operators.errorcontrol.php#85042
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
http://us3.php.net/manual/en/language.operators.errorcontrol.php#94004
Be aware of using error control operator in statements before
include() like this:
This cause, that error reporting level is set to zero also for the
included file. So if there are some errors in the included file, they
will be not displayed.
最后,可以集中管理所有应用程序的错误处理,而不仅仅是针对特定功能。