Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Feb 4, 2025

Currently, the only way to fetch the current error and exception handlers is to push a new one before restoring it:

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

This PR adds get_error_handler(), get_exception_handler() functions to address this use-case. They return the last value passed to set_error_handler() or set_exception_handler(), respectively, or NULL if no handler was set.

Related: symfony/symfony#58372 (comment).

cc @lyrixx @nicolas-grekas

@@ -117,11 +117,15 @@ function set_error_handler(?callable $callback, int $error_levels = E_ALL) {}

function restore_error_handler(): true {}

function get_error_handler(): mixed {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you have a return type of ?callable ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's better

@nielsdos
Copy link
Member

nielsdos commented Feb 4, 2025

I believe you can use RETURN_COPY instead of RETURN_ZVAL because those handlers can't be references, so the generated code will be a bit shorter by using RETURN_COPY then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants