@@ -101,6 +101,7 @@ class ErrorHandler
101101 private static $ reservedMemory ;
102102 private static $ stackedErrors = array ();
103103 private static $ stackedErrorLevels = array ();
104+ private static $ exitCode = 0 ;
104105
105106 /**
106107 * Same init value as thrownErrors.
@@ -477,6 +478,9 @@ public function handleError($type, $message, $file, $line)
477478 */
478479 public function handleException ($ exception , array $ error = null )
479480 {
481+ if (null === $ error ) {
482+ self ::$ exitCode = 255 ;
483+ }
480484 if (!$ exception instanceof \Exception) {
481485 $ exception = new FatalThrowableError ($ exception );
482486 }
@@ -562,7 +566,7 @@ public static function handleFatalError(array $error = null)
562566 return ;
563567 }
564568
565- if (null === $ error ) {
569+ if ($ exit = null === $ error ) {
566570 $ error = error_get_last ();
567571 }
568572
@@ -586,15 +590,20 @@ public static function handleFatalError(array $error = null)
586590 } else {
587591 $ exception = new FatalErrorException ($ handler ->levels [$ error ['type ' ]].': ' .$ error ['message ' ], 0 , $ error ['type ' ], $ error ['file ' ], $ error ['line ' ], 2 , true , $ trace );
588592 }
589- } elseif (!isset ($ exception )) {
590- return ;
591593 }
592594
593595 try {
594- $ handler ->handleException ($ exception , $ error );
596+ if (isset ($ exception )) {
597+ self ::$ exitCode = 255 ;
598+ $ handler ->handleException ($ exception , $ error );
599+ }
595600 } catch (FatalErrorException $ e ) {
596601 // Ignore this re-throw
597602 }
603+
604+ if ($ exit && self ::$ exitCode ) {
605+ register_shutdown_function ('register_shutdown_function ' , function () { exit (self ::$ exitCode ); });
606+ }
598607 }
599608
600609 /**
0 commit comments