Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 5fe2066

Browse files
[Debug] Fix fatal error handlers on PHP 7
1 parent 3b97c83 commit 5fe2066

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

ErrorHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function handleException($exception, array $error = null)
469469
}
470470
$type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
471471

472-
if ($this->loggedErrors & $type) {
472+
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
473473
$e = array(
474474
'type' => $type,
475475
'file' => $exception->getFile(),
@@ -496,9 +496,9 @@ public function handleException($exception, array $error = null)
496496
} else {
497497
$message = 'Uncaught Exception: '.$exception->getMessage();
498498
}
499-
if ($this->loggedErrors & $e['type']) {
500-
$this->loggers[$e['type']][0]->log($this->loggers[$e['type']][1], $message, $e);
501-
}
499+
}
500+
if ($this->loggedErrors & $type) {
501+
$this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e);
502502
}
503503
if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
504504
foreach ($this->getFatalErrorHandlers() as $handler) {

Exception/FatalThrowableError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(\Throwable $e)
2727
$message = 'Type error: '.$e->getMessage();
2828
$severity = E_RECOVERABLE_ERROR;
2929
} else {
30-
$message = 'Fatal error: '.$e->getMessage();
30+
$message = $e->getMessage();
3131
$severity = E_ERROR;
3232
}
3333

Tests/ErrorHandlerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,24 @@ public function testHandleFatalError()
413413
}
414414
}
415415

416+
/**
417+
* @requires PHP 7
418+
*/
419+
public function testHandleErrorException()
420+
{
421+
$exception = new \Error("Class 'Foo' not found");
422+
423+
$handler = new ErrorHandler();
424+
$handler->setExceptionHandler(function () use (&$args) {
425+
$args = func_get_args();
426+
});
427+
428+
$handler->handleException($exception);
429+
430+
$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $args[0]);
431+
$this->assertSame("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement?", $args[0]->getMessage());
432+
}
433+
416434
public function testHandleFatalErrorOnHHVM()
417435
{
418436
try {

0 commit comments

Comments
 (0)