diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 78dfba19b1..46bcc33f67 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -101,6 +101,7 @@ class ErrorHandler private static $reservedMemory; private static $stackedErrors = array(); private static $stackedErrorLevels = array(); + private static $exitCode = 0; /** * Same init value as thrownErrors. @@ -477,6 +478,9 @@ class ErrorHandler */ public function handleException($exception, array $error = null) { + if (null === $error) { + self::$exitCode = 255; + } if (!$exception instanceof \Exception) { $exception = new FatalThrowableError($exception); } @@ -562,7 +566,7 @@ class ErrorHandler return; } - if (null === $error) { + if ($exit = null === $error) { $error = error_get_last(); } @@ -586,15 +590,21 @@ class ErrorHandler } else { $exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace); } - } elseif (!isset($exception)) { - return; } try { - $handler->handleException($exception, $error); + if (isset($exception)) { + self::$exitCode = 255; + $handler->handleException($exception, $error); + } } catch (FatalErrorException $e) { // Ignore this re-throw } + + if ($exit && self::$exitCode) { + $exitCode = self::$exitCode; + register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); }); + } } /**