3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_error_handler(function (int $no, string $str): bool { var_dump('DEBUG: ' . $str); global $level; if ($level !== null) { error_reporting($level); // restore error level unset($level); return true; // handle the internal/helper error } // supress the current error output $level = error_reporting(); error_reporting(0); trigger_error('internal'); // trigger internal/helper error to restore the error level return false; // not handled to set the error_get_last() }); error_reporting(E_ALL); // to show the error, has no effect if the handler is called or not (expected, documented) var_dump(error_reporting()); trigger_error('custom'); // trigger_error('internal2'); // uncomment to reproduce the desired behaviour var_dump(error_get_last()['message']); var_dump(error_reporting());

preferences:
51.31 ms | 408 KiB | 5 Q