The function trigger_error will terminate the script if $error_level is equal or higher than E_USER_ERROR.
If you write your own error handler you will have to do these yourself.
Example in which we assume the global LOG constant points to a PSR2 logging interface.
<?php
set_error_handler( function ($errno, $errstr, $errfile, $errline) {
if( 0 === error_reporting() ) {
return false;
}
switch($errno) {
default:
LOG->error( "Unknown error type: [$errno] $errstr", [ 'file' => $errfile, '@' => $errline ] );
exit(1);
case E_USER_ERROR: case E_WARNING: LOG->error( $errstr, [ 'file' => $errfile, '@' => $errline ] );
exit(1);
case E_USER_DEPRECATED:
case E_DEPRECATED:
LOG->error( "DEPRECATED $errstr", [ 'file' => $errfile, '@' => $errline ] );
break;
case E_USER_WARNING: case E_NOTICE: LOG->warning( $errstr, [ 'file' => $errfile, '@' => $errline ] );
break;
case E_USER_NOTICE:
LOG->notice( $errstr, [ 'file' => $errfile, '@' => $errline ] );
break;
case E_ERROR: case E_RECOVERABLE_ERROR:
LOG->critical( $errstr, [ 'file' => $errfile, '@' => $errline ] );
exit(1);
}
return true;
} );
?>