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