Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e59c71

Browse filesBrowse files
committed
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
2 parents ebdff46 + c7d3b45 commit 7e59c71
Copy full SHA for 7e59c71

File tree

3 files changed

+23
-5
lines changed
Filter options

3 files changed

+23
-5
lines changed

‎src/Symfony/Component/Debug/ErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/ErrorHandler.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function handleException($exception, array $error = null)
469469
}
470470
$type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
471471

472-
if ($this->loggedErrors & $type) {
472+
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
473473
$e = array(
474474
'type' => $type,
475475
'file' => $exception->getFile(),
@@ -496,9 +496,9 @@ public function handleException($exception, array $error = null)
496496
} else {
497497
$message = 'Uncaught Exception: '.$exception->getMessage();
498498
}
499-
if ($this->loggedErrors & $e['type']) {
500-
$this->loggers[$e['type']][0]->log($this->loggers[$e['type']][1], $message, $e);
501-
}
499+
}
500+
if ($this->loggedErrors & $type) {
501+
$this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e);
502502
}
503503
if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
504504
foreach ($this->getFatalErrorHandlers() as $handler) {

‎src/Symfony/Component/Debug/Exception/FatalThrowableError.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FatalThrowableError.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(\Throwable $e)
2727
$message = 'Type error: '.$e->getMessage();
2828
$severity = E_RECOVERABLE_ERROR;
2929
} else {
30-
$message = 'Fatal error: '.$e->getMessage();
30+
$message = $e->getMessage();
3131
$severity = E_ERROR;
3232
}
3333

‎src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,24 @@ public function testHandleFatalError()
413413
}
414414
}
415415

416+
/**
417+
* @requires PHP 7
418+
*/
419+
public function testHandleErrorException()
420+
{
421+
$exception = new \Error("Class 'Foo' not found");
422+
423+
$handler = new ErrorHandler();
424+
$handler->setExceptionHandler(function () use (&$args) {
425+
$args = func_get_args();
426+
});
427+
428+
$handler->handleException($exception);
429+
430+
$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $args[0]);
431+
$this->assertSame("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement?", $args[0]->getMessage());
432+
}
433+
416434
public function testHandleFatalErrorOnHHVM()
417435
{
418436
try {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.