简体   繁体   English

在PHP中查看@抑制错误

[英]View @ supressed errors in php

I know you can use @ to suppress errors. 我知道你可以使用@来抑制错误。 But is there anyway you can make php ignore @ ? 但无论如何你可以让php忽略@?

In my case, I have to use a 3th party script that uses @, the script is huge and I'm having a hard time finding out where it dies. 在我的情况下,我必须使用使用@的第3方脚本,脚本很大,我很难找到它死的地方。

When you use the PHP Xdebug extension you can ignore the error control operator @ by using this config setting : 使用PHP Xdebug扩展时 ,可以使用此配置设置忽略错误控制操作符 @

xdebug.scream = 1

This disables the @ (shut-up) operator so that notices, warnings and errors are no longer hidden. 这将禁用@(关闭)运算符,以便不再隐藏通知,警告和错误。

有一个尖叫延伸打破沉默。

Every custom error handler receives suppressed error messages: 每个自定义错误处理程序都会收到抑制错

set_error_handler("var_dump");

Just an example. 只是一个例子。 You would normally choose a nicer reporting function. 您通常会选择更好的报告功能。

But is there anyway you can make php ignore @ ? 但无论如何你可以让php忽略@?

I don't think so, no, not without an extension as shown by @deceze. 我不这么认为,不,没有@deceze所示的扩展。

You could set up a custom error handler though. 您可以设置自定义错误处理程序 If you configure that to ignore the error_reporting() setting, which is 0 when inside a function that was called with @ , you can output the error there. 如果配置为忽略error_reporting()设置,当在使用@调用的函数内时为0 ,则可以在那里输出错误。

You can use 您可以使用

print_r(error_get_last());

to get the last generated error after that script so you can catch the supressed errors. 在该脚本之后获取最后生成的错误,以便捕获被抑制的错误。

Further reading error_get_last() 进一步阅读error_get_last()

ini_set('scream.enabled', true);

You need to install the scream pecl extension: 您需要安装scream pecl扩展:

http://www.php.net/manual/en/book.scream.php http://www.php.net/manual/en/book.scream.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM