# [RFC] Add get_error_handler(), get_exception_handler() functions

- Thread: https://externals.io/message/126372
- Original archive: https://news-web.php.net/php.internals/126372
- Started by Arnaud Le Blanc on 2025-02-11T13:18:19+00:00
- Messages: 2
- RFC: Add get_error_handler(), get_exception_handler() functions (Implemented (PHP 8.5)) — https://externals.io/rfc/get-error-exception-handler.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #126372 — Arnaud Le Blanc — 2025-02-11T13:18:19+00:00

URL: https://externals.io/message/126372#126372

Hi,

At the moment, there is no 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 feels hackish and is error-prone.

I would like to propose the addition of two new functions:
 `get_error_handler()`, `get_exception_handler()` to address this:

https://wiki.php.net/rfc/get-error-exception-handler

Best Regards,
Arnaud

---

## #126440 — Jordi Boggiano — 2025-02-18T10:25:42+00:00

URL: https://externals.io/message/126372#126440 · In reply to: #126372

> At the moment, there is no 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 feels hackish and is error-prone.

Sounds good to me, straightforward clean-up of a weird API.

Best,
Jordi

-- 
Jordi Boggiano
@seldaek - https://seld.be
