10000 [Debug] Fix fatal error handlers on PHP 7 by nicolas-grekas · Pull Request #18737 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Debug] Fix fatal error handlers on PHP 7 #18737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Debug] Fix fatal error handlers on PHP 7
  • Loading branch information
nicolas-grekas committed May 9, 2016
commit c7d3b4584170db75011b48698734132af2978edc
8 changes: 4 additions & 4 deletions src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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