-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add internal API for Error Notification Callbacks #4555
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
88d0486
to
28b1529
Compare
One thing to note here is that there's some places that directly call zend_error_cb. |
Needs a rebase after #5639. |
28b1529
to
ccffa02
Compare
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.
This looks reasonable to me.
Zend/zend.h
Outdated
@@ -351,6 +351,22 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current); | |||
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current); | |||
ZEND_API void zend_restore_error_handling(zend_error_handling *saved); | |||
|
|||
typedef void (*zend_error_notify_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); |
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.
Here and elsewhere, do not use const uint32_t
, just uint32_t
. This makes particularly little sense inside signatures.
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.
zend_error_cb also has const uint32_t
in signature, thats where I copied it from. Probably good to have another PR to clean that up, because it affects at least ext/soap
I'm a bit busy so I went through it quickly. Checking one thing:
Can you give me an example? I have avoided the previous hooks because I was aware of the unreliability, so I'm not familiar this case. |
@morrisonlevi In |
@krakjoe @nikic @Girgias @morrisonlevi i am going to merge this next week unless you have comments. |
7eb1b74
to
87df1a7
Compare
merged with 6c8b94e |
|
||
BEGIN_EXTERN_C() | ||
|
||
void zend_register_error_notify_callback(zend_error_notify_cb callback); |
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.
Should it be ZEND_API?
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.
Yeah, it should.
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.
oops, will fix it
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.
Ah you already committed this yesterday, thanks
PHP Extensions are able to hook into the error mechanism of the Zend Engine by overwriting the
zend_error_cb
callback. This callback has a lot of responsibilities though (display, repeated error supression, logging, exception conversion), so that overwriting is quite difficult. A few extensions also overwrite the error handler in a way that previous handlers are not called anymore (xdebug), making it unreliable.This PR introduces a new API that allows extensions to register global error notification handlers.
php_error_cb
, so that it is guaranteed they are always called when an error occurs, even whenzend_error_cb
is overwritten. This also means that the notification happens before repeatable errors are ignored and last_error is updated.Example
As an example I was able to refactor the inlined DTrace notification handling into the new API.
report_zend_debug
code is also be a candidate for being a notification callback and was migrated. This debug code is not used anywhere, maybe it should be removed though?Usage Example:
Questions
zend_instrument_install_error_callback(cb)
Out of scope
The error mechanism can use a larger cleanup as discussed in the Improved Error Callbacks Mechanism RFC that was never implemented.
This PR is only about a reliable notification callback for now. Other changes may follow this.