diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index c3cae81bde..33779af325 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -469,7 +469,7 @@ class ErrorHandler } $type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR; - if ($this->loggedErrors & $type) { + if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) { $e = array( 'type' => $type, 'file' => $exception->getFile(), @@ -496,9 +496,9 @@ class ErrorHandler } else { $message = 'Uncaught Exception: '.$exception->getMessage(); } - if ($this->loggedErrors & $e['type']) { - $this->loggers[$e['type']][0]->log($this->loggers[$e['type']][1], $message, $e); - } + } + if ($this->loggedErrors & $type) { + $this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e); } if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) { foreach ($this->getFatalErrorHandlers() as $handler) { diff --git a/src/Symfony/Component/Debug/Exception/FatalThrowableError.php b/src/Symfony/Component/Debug/Exception/FatalThrowableError.php index 6ff5ecdaff..34f43b17b1 100644 --- a/src/Symfony/Component/Debug/Exception/FatalThrowableError.php +++ b/src/Symfony/Component/Debug/Exception/FatalThrowableError.php @@ -27,7 +27,7 @@ class FatalThrowableError extends FatalErrorException $message = 'Type error: '.$e->getMessage(); $severity = E_RECOVERABLE_ERROR; } else { - $message = 'Fatal error: '.$e->getMessage(); + $message = $e->getMessage(); $severity = E_ERROR; } diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index c107c0c7cb..12f2fcb40b 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -413,6 +413,24 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase } } + /** + * @requires PHP 7 + */ + public function testHandleErrorException() + { + $exception = new \Error("Class 'Foo' not found"); + + $handler = new ErrorHandler(); + $handler->setExceptionHandler(function () use (&$args) { + $args = func_get_args(); + }); + + $handler->handleException($exception); + + $this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $args[0]); + $this->assertSame("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement?", $args[0]->getMessage()); + } + public function testHandleFatalErrorOnHHVM() { try {