PHP does not provide a direct way to fetch the currently registered error or exception handlers. Users who need to inspect these handlers must resort to a workaround that temporarily sets a new handler and then immediately restores the previous one:
$current_error_handler = set_error_handler('valid_callback'); restore_error_handler();
This workaround is cumbersome and error-prone.
This RFC proposes two new functions that allow to query the current error/exception handlers in a more direct way:
function get_error_handler(): ?callable
function get_exception_handler(): ?callable
The functions return the currently defined error and exception handlers, respectively. If no handler is in place, null
is returned.
The returned handler is the exact callback value that was passed to set_error_handler()
or set_exception_handler()
to define it.
set_error_handler(null); get_error_handler(); // null
$handler = [$this, 'error_handler']; set_error_handler($handler); get_error_handler() === $handler; // true
$new_handler = $this->error_handler(...); $old_handler = set_error_handler($new_handler); get_error_handler() === $new_handler; // true restore_error_handler(); get_error_handler() === $old_handler; // true
The function names get_error_handler
, get_exception_handler
will no longer be available within the global namespace.
Next 8.x.
Yes or no vote. 2/3 required to pass.
After the project is implemented, this section should contain