@@ -101,6 +101,7 @@ class ErrorHandler
101
101
private static $ reservedMemory ;
102
102
private static $ stackedErrors = array ();
103
103
private static $ stackedErrorLevels = array ();
104
+ private static $ exitCode = 0 ;
104
105
105
106
/**
106
107
* Same init value as thrownErrors.
@@ -477,6 +478,9 @@ public function handleError($type, $message, $file, $line)
477
478
*/
478
479
public function handleException ($ exception , array $ error = null )
479
480
{
481
+ if (null === $ error ) {
482
+ self ::$ exitCode = 255 ;
483
+ }
480
484
if (!$ exception instanceof \Exception) {
481
485
$ exception = new FatalThrowableError ($ exception );
482
486
}
@@ -562,7 +566,7 @@ public static function handleFatalError(array $error = null)
562
566
return ;
563
567
}
564
568
565
- if (null === $ error ) {
569
+ if ($ exit = null === $ error ) {
566
570
$ error = error_get_last ();
567
571
}
568
572
@@ -586,15 +590,20 @@ public static function handleFatalError(array $error = null)
586
590
} else {
587
591
$ exception = new FatalErrorException ($ handler ->levels [$ error ['type ' ]].': ' .$ error ['message ' ], 0 , $ error ['type ' ], $ error ['file ' ], $ error ['line ' ], 2 , true , $ trace );
588
592
}
589
- } elseif (!isset ($ exception )) {
590
- return ;
591
593
}
592
594
593
595
try {
594
-
8704
$ handler ->handleException ($ exception , $ error );
596
+ if (isset ($ exception )) {
597
+ self ::$ exitCode = 255 ;
598
+ $ handler ->handleException ($ exception , $ error );
599
+ }
595
600
} catch (FatalErrorException $ e ) {
596
601
// Ignore this re-throw
597
602
}
603
+
604
+ if ($ exit && self ::$ exitCode ) {
605
+ register_shutdown_function ('register_shutdown_function ' , function () { exit (self ::$ exitCode ); });
606
+ }
598
607
}
599
608
600
609
/**
0 commit comments