-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[RFC] Add get_error_handler(), get_exception_handler() functions #17693
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
Conversation
I believe you can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation makes sense to me, I wonder however if as a follow-up we should refactor how the error/exceptions handlers are stored (e.g. as an FCC instead of a zval) so that we can return a Closure that is guaranteed to always be valid.
As callable
still has scope implications and I'm not actually sure returning it as is necessarily makes it callable in the scope these new functions are called.
Does it make sense to add two test cases?
And the same for |
Unfortunately I can not change that because the behaviour is specified explicitly in the RFC: "The returned handler is the exact callback value that was passed to Is the scope the only issue making the value potentially not callable? An alternative solution to that problem may be to change Currently, |
Any plans adding also |
@janedbal I didn't plan to. Do you have example use cases? |
Thanks everyone for the reviews! |
Yes. We built a tool that tries to detect "memory leaks" by scanning all global space (static vars, closure uses, ...). One of the few places that is currently not accessible at all are shutdown handlers. For reference, here is some initial version of that. |
This makes sense, thanks! I'm adding this on my TODO (but if anyone wants to take care of this, feel free). |
This PR was squashed before being merged into the 1.x branch. Discussion ---------- Add `get_*_handler` polyfills Here is the polyfill of newly implemented `get_error_handler` and `get_exception_handler`. I have created the default files for PHP 8.5 polyfills. The tests are taken from php/php-src#17693, but some cannot be completed due to new PHP 8 syntax. There are some issues with the error handler in the tests, I can't figure out why. If someone can help, that would be great! 😅 This seems to be related to the TestListenerTrait, I think. [RFC](https://wiki.php.net/rfc/get-error-exception-handler) Commits ------- d791faa Add `get_*_handler` polyfills
Currently, the only way to fetch the current error and exception handlers is to push a new one before restoring it:
This PR adds
get_error_handler()
,get_exception_handler()
functions to address this use-case. They return the last value passed toset_error_handler()
orset_exception_handler()
, respectively, orNULL
if no handler was set.RFC: https://wiki.php.net/rfc/get-error-exception-handler
Related: symfony/symfony#58372 (comment).
cc @lyrixx @nicolas-grekas