-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Zend\Stdlib\ErrorHandler breaks custom error handlers #7497
Comments
Yes: because it's the most common use case.
The specific problem you're seeing is due to the default behavior of
By default, the error handler we register is using Let's look at the signature: public static function registerErrorHandler(Logger $logger, $continueNativeHandler = false) That second argument is a flag that determines the return value from the handler. Internally, we do this: return !$continueNativeHandler; The way PHP works, it only invokes other registered error handlers if the return value is boolean
So, by default, we return boolean One point: If you are constructing $logger = $callback();
\Zend\Log\Logger::registerErrorHandler($logger, true);
return $logger; |
Thank you for your answer. Maybe I wasn’t clear enough. I created my own error handler which makes use of the Logger and this error handler is only called for the first error. My error handler is very similar to the Logger error handler. $logger = new Zend\Log\Logger();
$streamOrUrl = array('stream' => 'php://stdout');
$writer = new Zend\Log\Writer\Stream($streamOrUrl);
$logger->addWriter($writer);
Zend\Log\Logger::registerErrorHandler($logger, false);
trigger_error('Some notice');
trigger_error('Some other notice'); The output I expect:
The output I get:
When I change
Zf 2.4, php 5.5 / 5.6 tested on win7 and ubuntu Whatever I do the Logger only logs the first error. In fact the Logger error handler is not even called for the second error but the native error handler is called.
I suppose that’s because of some strange behaviour of set_error_handler and restore_error_handler, when the optional second parameter is used. When I modify the - public static function start($errorLevel = \E_WARNING)
+ public static function start()
{
if (!static::$stack) {
- set_error_handler(array(get_called_class(), 'addError'),$errorLevel);
+ set_error_handler(array(get_called_class(), 'addError'));
} I get my expected result:
By removing the |
That sounds like a PHP bug, then. It's always best to specify the error level when calling |
@lukasclausen I was pointed out to this issue and I tried to reproduce your issue with as less code as possible. See e.g. https://3v4l.org/JdWWp |
See for an example https://3v4l.org/6hW5O The bug occurs when you have a nested error handler which is registered inside the current error handler and unregisterd before the original error handler finishes. It only occurs if the nested error handler is set for specific error types. The error handler the falls back to the php default error handler. If the nested error handler is not limited (line 12) everythings fine: As a workaround I reset the main error handler at the end of each call: I can reproduce it with both xdebug enabled and disabled. |
Understood, thanks for the explanations. |
Okay, but the bug has not been fixed since then. |
Needs to just be reported again then, ideally as failing test pr.
…On 5 May 2017 5:39 p.m., "Maciej Holyszko" ***@***.***> wrote:
Okay, but the bug has not been fixed since then.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#7497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakCeqCxdC5vp8XJQEt-XGX9oc-MQ0ks5r20K9gaJpZM4ESRRc>
.
|
I know this issue has already been discussed, but it still exists. The Logger error handler only works for the first triggered error:
The second notice will not be logged. That's because of the
Zend\Stdlib\ErroHandler::start/stop()
call in the log writers. I know this error handler calls are there for good reason, but they break the main custom error handler. In more detail the nested set_error_handler calls inside Zend\Stdlib\ErroHandler breaks it. I found out that the second parameter of set_error_handler causes the error when used inside of an error_handler. I suppose that's a php bug. The following won't work for the second error:When changing
set_error_handler($error_handler2,E_WARNING);
toset_error_handler($error_handler2);
the code works as expected. So removing the second argument ofset_error_handler
inside Zend\Stdlib\ErroHandler start for me also fixes my logger error handler problems. Is there a reason whyZend\Stdlib\ErroHandler::start
is limited to E_WARNINGS by default?The text was updated successfully, but these errors were encountered: