function在php中,为什么在PHP中使用@function(禁用每个函数的错误报告)是不好的做法?...

有一些原因使用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.

最后,可以集中管理所有应用程序的错误处理,而不仅仅是针对特定功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值