Skip to content

Commit 567cbaa

Browse files
bug #26568 [Debug] Reset previous exception handler earlier to prevent infinite loop (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Reset previous exception handler earlier to prevent infinite loop | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26438 | License | MIT | Doc PR | - Commits ------- f7e1bb0 [Debug] Reset previous exception handler ealier to prevent infinite loop
2 parents 2fb2ed0 + f7e1bb0 commit 567cbaa

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,16 @@ public function handleException($exception, array $error = null)
544544
}
545545
}
546546
}
547+
$exceptionHandler = $this->exceptionHandler;
548+
$this->exceptionHandler = null;
547549
try {
548-
if (null !== $this->exceptionHandler) {
549-
return \call_user_func($this->exceptionHandler, $exception);
550+
if (null !== $exceptionHandler) {
551+
return \call_user_func($exceptionHandler, $exception);
550552
}
551553
$handlerException = $handlerException ?: $exception;
552554
} catch (\Exception $handlerException) {
553555
} catch (\Throwable $handlerException) {
554556
}
555-
$this->exceptionHandler = null;
556557
if ($exception === $handlerException) {
557558
self::$reservedMemory = null; // Disable the fatal error handler
558559
throw $exception; // Give back $exception to the native handler

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,17 @@ public function testLegacyInterface()
530530
throw $e;
531531
}
532532
}
533+
534+
/**
535+
* @expectedException \Exception
536+
*/
537+
public function testCustomExceptionHandler()
538+
{
539+
$handler = new ErrorHandler();
540+
$handler->setExceptionHandler(function ($e) use ($handler) {
541+
$handler->handleException($e);
542+
});
543+
544+
$handler->handleException(new \Exception());
545+
}
533546
}

0 commit comments

Comments
 (0)