Open gaambo opened 4 months ago
I've got a simple workaround running, by extending PhpErrorController
: https://gist.github.com/gaambo/6ea135cdc28fe3b30e61c2713db78040
I still need to test this further, I'm just getting started with Wonolog.
But if this works and it's in your interest, I can draft up a PR.
Thanks @gaambo
It never worked restoring the previous handler, but before PHP 8.3, it did not trigger an infinite loop either.
In the comment in the official docs you linked, where the exception is re-thrown, there is no mention of an endless loop because that is a new thing.
This is a bug, but it is only visible on PHP 8.3, which we are yet testing for...
If you can do a PR with the fix, I'm definitively interested, but I would like to avoid the requirement that Php_Error_Controller::register()
must be called before bootstrap ()
for it to work.
Moreover, it looks like you're using Wonolog v1. You should look into v2 for more modern PHP support, or even in the upcoming v3
It might be something like this: https://3v4l.org/jme3m
The Configurator::setupPhpErrorListener()
method in that 3v4l above would be here in Wonolog: https://github.com/inpsyde/Wonolog/blob/3.x/src/Configurator.php#L1013
It never worked restoring the previous handler, but before PHP 8.3, it did not trigger an infinite loop either.
Very interesting finding, thank you @gmazzap.
If you can do a PR with the fix, I'm definitively interested, but I would like to avoid the requirement that Php_Error_Controller::register() must be called before bootstrap () for it to work.
That is just for my custom implementation for Php_Error_Controller, because the setup happens in the constructor. If it's in the framework, that's not required. I also just wanted to share the workaround for anyone coming here.
Moreover, it looks like you're using Wonolog v1. You should look into v2 for more modern PHP support, or even in the upcoming v3
I wasn't sure about their stability and therefore stuck to v1. But we'll probably want to use a 3rd party handler as well that requires at least monolog v2, so we'll probably update soon.
Should I create a PR for v1, v2 or v3? 😬
Having the same problem. Is a fix going to be implemented for this?
Description of the bug
I'm running into an infinite recursion when throwing an exception somehwere. The
PhpErrorController:on_exception
exception handler is correctly called and logs the exception, but it then callsrestore_exception_handler
and re-throws the Exception which triggers the same function again. According to a comment in the PHP docs:Therefore it runs the same method over and over again.
Reproduction instructions
init
)on_exception
method get called over and over againExpected behavior
In my case I just wanted to test the logging by manually throwing an exception. But when a real one throws, it loggs a huge amount of the same message and runs into fatal error with "Maximum call stack size".
I found out that you can use
set_exception_handler(null);
to reset it to the PHP defaults exception handler. Then theon_fatal
will be called, because the exception is unhandled.Another possibility would be to save the return-value of
set_exception_handler
(= the previous one) inController::log_php_errors
and restore to it later.Environment info
Relevant log output
Additional context
No response
Code of Conduct