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.

Community
  • 1
  • 1
dm03514
  • 54,664
  • 18
  • 108
  • 145
  • 1
    I'm missing something here. There's code designed to do exactly what you want(http://stackoverflow.com/questions/10520390/stop-script-execution-upon-notice-warning) but you don't want to use that? What magic are you looking for? – SomeKittens Aug 21 '12 at 16:15
  • 1
    Some might thing it traditional to wait for a response before downvoting the question... – Martin Milan Aug 21 '12 at 16:16
  • @SomeKittens I work for a boutique and I have about 30 different sites in active development. I was hoping there was a way I could do something equivelent to the link in a centralized location ie php.ini. I am not looking for a code solution but a configuration solution, I found a code solution in the link posted in my question. I will try and update question to be clearer. – dm03514 Aug 21 '12 at 16:18

5 Answers5

3

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."

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
1

Use set_error_handler to throw an exception inside the error handler.

Uncaught the exception will stop execution.

Mihai Stancu
  • 15,848
  • 2
  • 33
  • 51
1

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");
James
  • 13,092
  • 1
  • 17
  • 19
0

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

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

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.

robinhook
  • 11
  • 2