Make PHP exit on E_ALL|E_STRICT

Hi all,

I’d like to be able to make any script stop processing, basically exit(), whenever any type of error is discovered. For example, if I get an undefined variable error, the error will output, but the script continues to run. Is it possible to make the script to exit?

Thanks!

I think you can control it using try catch.
Just play with it I guess.

That’s not really an option for me since it would mean modifying loads of code. I was kinda looking for a quick solution. I’ve come across server environments before which stop on any kind of PHP error but I can’t seem to find the right settings.

Try searching for “PHP [COLOR=#793862][FONT=Fira Sans]set_error_handler”.

Tapped in from a tablet :([/FONT][/COLOR]

Try this.


set_error_handler(function ( $errno ,  $errstr, $errfile, $errline, $errcontext ) {
  echo "Error Number $errno: $errstr in file $errfile at line $errline.\
";
  print_r($errcontext);
  exit;
});

This traps ALL errors and sends a message, then dies immediately. You can get the error type by referencing the error numbers against the PHP error constants given here.