Reputation: 55962
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.
Upvotes: 0
Views: 1505
Reputation: 11
Seen with PHP 5.5 zts/non-zts, the module Suhosin has this default behavior* with E_WARNING on eval & func blacklist parameters.
*stop script at first warning.
Upvotes: 0
Reputation: 13501
A custom error handler would be the easiest way I know of to do this. They're not complicated - you could simply write a function that terminates the script immediately, and instruct PHP to use it for error handling - a (simple) example:
function my_error_handler($num,$msg) {
die();
}
set_error_handler("my_error_handler");
Upvotes: 1
Reputation: 16107
Use set_error_handler to throw an exception inside the error handler.
Uncaught the exception will stop execution.
Upvotes: 1
Reputation: 75629
You app shall register your own error handler as soon as possible. If any warning or error hit, just abort there. Please note syntax errors won't be trapped that way. See http://php.net/manual/en/function.set-error-handler.php
Upvotes: 0
Reputation: 191749
From what I can tell, there is no way to do this outside of creating a custom error handler that stops execution immediately. However, it would only take about four lines to do that (or use the answers/comments that SomeKittens posted).
Sorry to say but the answer to your questions is "no."
Upvotes: 3