-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
error_get_last()
is not set when errors are logged
#5587
Comments
If you rely on
|
I want to share another scenario I faced. I recognise Error handler is global state. I decided to avoid relying on that global state (that could be overridden by PHPUnit, but also by whatever library I use) and put my logic to retrieve internal-error behind one-time-error-handler wrapper - thus also not using Sharing here, as maybe someone will like to get inspired by this: |
interesting! thanks for good news! Overall, i'm happy to wait for this to be released to upgrade Fixer to v10 afterwards. [ Same time, I would love to get rid of any custom error handling in my codebase... and hope to see this set up in PHP itself properly ;) ] |
related with #5428
Summary
Current behavior
error_get_last()
is not set when errors are logged (PHPUnit error handler is active). The errors are logged by default which is a good. But the current impl. of the error handler causes code that relies onerror_get_last()
set after a core php function has returned a failure like:to fail as
error_get_last()
is empty.This is because the current impl. of the error handler returns
true
[1] when an error is handled. The php docs say [2]:[1] https://github.com/sebastianbergmann/phpunit/blob/10.4.2/src/Runner/ErrorHandler.php#L144
[2] https://www.php.net/manual/en/function.set-error-handler.php
The issue is present since PHPUnit 10, in PHPUnit 9 and lower
error_get_last()
was set correctly.How to reproduce
Expected behavior
The PHPUnit handler should:
error_get_last()
result, the result must be the same /w and /wo PHPUnit error handler activeI tried to workaround about this issue https://3v4l.org/kS1vM/rfc#vgit.master but if the output is suppressed by lowering the reporting level when handling the error, it seems there is no way to restore the level back immediatelly after the error handling is finished.
I belive the solution is to modify the PHPUnit error handler:
false
when handling the error - it will let php to handle the error nativelyerror_reporting()
level and set it toerror_reporting(error_reporting() & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))
when the handler activates (the listed error levels cannot be handled by an user handler [2])WithoutErrorHandler
attribute neededThe text was updated successfully, but these errors were encountered: