Skip to content

Commit c6506c4

Browse files
minor symfony#54189 [ErrorHandler] Fix exit code when an exception occurs and the exception handler has been unregistered (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Fix exit code when an exception occurs and the exception handler has been unregistered | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#53946 | License | MIT PHP 8.3 introduced a change (see php/php-src#13446) that highlighted a fragility in ErrorHandler::handleFatalError, leading to the linked issued. This fixes it. What this doesn't fix is turning fatal errors into fake exceptions, which PHP 8.3 broke. For this, the fix is on the side of PHP. Testing is not obvious 🙈 Commits ------- f4ea95d [ErrorHandler] Fix exit code when an exception occurs and the exception handler has been unregistered
2 parents 9fe7efc + f4ea95d commit c6506c4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ public static function handleFatalError(?array $error = null): void
669669
set_exception_handler($h);
670670
}
671671
if (!$handler) {
672+
if (null === $error && $exitCode = self::$exitCode) {
673+
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
674+
}
675+
672676
return;
673677
}
674678
if ($handler !== $h) {
@@ -704,8 +708,7 @@ public static function handleFatalError(?array $error = null): void
704708
// Ignore this re-throw
705709
}
706710

707-
if ($exit && self::$exitCode) {
708-
$exitCode = self::$exitCode;
711+
if ($exit && $exitCode = self::$exitCode) {
709712
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
710713
}
711714
}

0 commit comments

Comments
 (0)