- var_dump: documentation ( source)
- error_get_last: documentation ( source)
- error_reporting: documentation ( source)
- set_error_handler: documentation ( source)
- trigger_error: documentation ( source)
<?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());