bug #18737 [Debug] Fix fatal error handlers on PHP 7 (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Debug] Fix fatal error handlers on PHP 7

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Currently, fatal error handlers are broken on PHP 7.

Commits
-------

c7d3b45 [Debug] Fix fatal error handlers on PHP 7
This commit is contained in:
Fabien Potencier 2016-05-10 11:50:18 -05:00
commit 7e59c71d9a
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;
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) {

View File

@ -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;
}

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()
{
try {