[Debug] Fix fatal error handlers on PHP 7

This commit is contained in:
Nicolas Grekas 2016-05-09 14:43:14 -05:00
parent 60bf201eba
commit c7d3b45841
3 changed files with 23 additions and 5 deletions

View File

@ -469,7 +469,7 @@ class ErrorHandler
} }
$type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR; $type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
if ($this->loggedErrors & $type) { if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
$e = array( $e = array(
'type' => $type, 'type' => $type,
'file' => $exception->getFile(), 'file' => $exception->getFile(),
@ -496,9 +496,9 @@ class ErrorHandler
} else { } else {
$message = 'Uncaught Exception: '.$exception->getMessage(); $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) { if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
foreach ($this->getFatalErrorHandlers() as $handler) { foreach ($this->getFatalErrorHandlers() as $handler) {

View File

@ -27,7 +27,7 @@ class FatalThrowableError extends FatalErrorException
$message = 'Type error: '.$e->getMessage(); $message = 'Type error: '.$e->getMessage();
$severity = E_RECOVERABLE_ERROR; $severity = E_RECOVERABLE_ERROR;
} else { } else {
$message = 'Fatal error: '.$e->getMessage(); $message = $e->getMessage();
$severity = E_ERROR; $severity = E_ERROR;
} }

View File

@ -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() public function testHandleFatalErrorOnHHVM()
{ {
try { try {