Skip to content

Commit d8d85f1

Browse files
bug symfony#25753 [Console] Fix restoring exception handler (nicolas-grekas, fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Fix restoring exception handler | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | ,p | Tests pass? | yes | Fixed tickets | symfony#25718 | License | MIT | Doc PR | - Commits ------- 0096449 [Console] Keep the modified exception handler 3fa1ad9 [Console] Fix restoring exception handler
2 parents f3ac9f5 + 0096449 commit d8d85f1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,18 @@ public function run(InputInterface $input = null, OutputInterface $output = null
163163
$exitCode = 1;
164164
}
165165
} finally {
166+
// if the exception handler changed, keep it
167+
// otherwise, unregister $renderException
166168
if (!$phpHandler) {
169+
if (set_exception_handler($renderException) === $renderException) {
170+
restore_exception_handler();
171+
}
167172
restore_exception_handler();
168173
} elseif (!$debugHandler) {
169-
$phpHandler[0]->setExceptionHandler(null);
174+
$finalHandler = $phpHandler[0]->setExceptionHandler(null);
175+
if ($finalHandler !== $renderException) {
176+
$phpHandler[0]->setExceptionHandler($finalHandler);
177+
}
170178
}
171179
}
172180

0 commit comments

Comments
 (0)