From 205d7ae3f715095d1ec71ede7ff05f0c1b6c9fae Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 Jan 2018 09:54:17 +0100 Subject: [PATCH] [Debug] Always decorate existing exception handlers to deal with fatal errors --- src/Symfony/Component/Debug/ErrorHandler.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index c0f07e256d..6a15f7b368 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -147,11 +147,14 @@ class ErrorHandler $handler = $prev[0]; $replace = false; } - if ($replace || !$prev) { - $handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException'))); - } else { + if (!$replace && $prev) { restore_error_handler(); } + if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] === $handler) { + restore_exception_handler(); + } else { + $handler->setExceptionHandler($prev); + } $handler->throwAt($levels & $handler->thrownErrors, true);