0

In php I have my error_reporting set to E_ALL.

I was wondering if there was a centralized way to make php STOP execution if any warnings are hit, or if any exceptions are hit. Completely stop execution. I have run into many bugs where I have typos in variables and script continues execution.

I found Strict mode in PHP? which gives a good code solution but am looking for some sort of configuration whcih would allow me to accomplish the same thing. Does one exist?

But I am trying to avoid having to a custom error handler for all of my projects? Does anyone know of a way to do this perhaps in php.ini? Preferably there would be a way to configure php so it would display the warning or error and just stop..

Thank you.

4

5 回答 5

3

据我所知,除了创建一个立即停止执行的自定义错误处理程序之外,没有办法做到这一点。但是,只需大约四行即可完成此操作(或使用 SomeKittens 发布的答案/评论)。

很抱歉,但您的问题的答案是“不”。

于 2012-08-21T16:16:01.890 回答
1

使用set_error_handler在错误处理程序中引发异常。

未捕获的异常将停止执行。

于 2012-08-21T16:16:37.937 回答
1

自定义错误处理程序将是我所知道的最简单的方法。它们并不复杂 - 您可以简单地编写一个立即终止脚本的函数,并指示 PHP 将其用于错误处理 - 一个(简单)示例:

function my_error_handler($num,$msg) {
 die();
}
set_error_handler("my_error_handler");
于 2012-08-21T16:16:45.430 回答
0

您的应用程序应尽快注册您自己的错误处理程序。如果出现任何警告或错误,请在此处中止。请注意语法错误不会被这样捕获。见http://php.net/manual/en/function.set-error-handler.php

于 2012-08-21T16:16:06.210 回答
0

PHP 5.5 zts/non-zts中看到,模块Suhosin具有此默认行为*,在 eval 和 func 黑名单参数上带有 E_WARNING。

*在第一次警告时停止脚本。

于 2015-08-09T17:05:34.300 回答