PHP lets you set an error handler with set_error_handler() and an exception handler with set_exception_handler(), but there was no direct way to ask which handler is currently set. This RFC from Arnaud Le Blanc adds two functions that answer that question: get_error_handler() and get_exception_handler().

Why change it

Before this, you had to use a workaround. Setting a new handler returns the old one, so you'd set a throwaway handler and immediately restore the previous one:

$current_error_handler = set_error_handler('valid_callback');
restore_error_handler();

The RFC calls this awkward and easy to get wrong.

Show me

The new functions have these signatures:

function get_error_handler(): ?callable
function get_exception_handler(): ?callable

Each returns the current handler, or null if none is set. You get back the exact value you passed in:

$handler = [$this, 'error_handler'];
set_error_handler($handler);

get_error_handler() === $handler; // true

It also tracks restore_error_handler() correctly:

$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

What it means for existing code

The only risk is a name clash. If your code already defines a global function named get_error_handler or get_exception_handler, it will conflict. Nothing else changes.

The vote

Accepted. The vote ran from March 5 to March 20, 2025 and passed 28 to 0, clearing the two-thirds majority it needed. It was merged into PHP 8.5.