Skip to content

Commit

Permalink
bug #18737 [Debug] Fix fatal error handlers on PHP 7 (nicolas-grekas)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed May 10, 2016
2 parents ebdff46 + c7d3b45 commit 7e59c71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -469,7 +469,7 @@ public function handleException($exception, array $error = null)
}
$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(),
Expand All @@ -496,9 +496,9 @@ public function handleException($exception, array $error = null)
} 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) {
Expand Down
Expand Up @@ -27,7 +27,7 @@ public function __construct(\Throwable $e)
$message = 'Type error: '.$e->getMessage();
$severity = E_RECOVERABLE_ERROR;
} else {
$message = 'Fatal error: '.$e->getMessage();
$message = $e->getMessage();
$severity = E_ERROR;
}

Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -413,6 +413,24 @@ public function testHandleFatalError()
}
}

/**
* @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 {
Expand Down

0 comments on commit 7e59c71

Please sign in to comment.