Skip to content

Commit 764c38a

Browse files
committed
Decouple ErrorHandler from ErrorRenderer component
1 parent 730969c commit 764c38a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\ErrorHandler\FatalErrorHandler\FatalErrorHandlerInterface;
2222
use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
2323
use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
24-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
2524

2625
/**
2726
* A generic ErrorHandler for the PHP engine.
@@ -414,7 +413,7 @@ public function handleError($type, $message, $file, $line)
414413
}
415414

416415
if (false !== strpos($message, "class@anonymous\0")) {
417-
$logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage();
416+
$logMessage = $this->parseAnonymousClass($message);
418417
} else {
419418
$logMessage = $this->levels[$type].': '.$message;
420419
}
@@ -539,7 +538,7 @@ public function handleException($exception, array $error = null)
539538

540539
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
541540
if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) {
542-
$message = (new FlattenException())->setMessage($message)->getMessage();
541+
$message = $this->parseAnonymousClass($message);
543542
}
544543
if ($exception instanceof FatalErrorException) {
545544
if ($exception instanceof FatalThrowableError) {
@@ -712,4 +711,15 @@ private function cleanTrace($backtrace, $type, $file, $line, $throw)
712711

713712
return $lightTrace;
714713
}
714+
715+
/**
716+
* Parse the error message by removing the anonymous class notation
717+
* and using the parent class instead if possible.
718+
*/
719+
private function parseAnonymousClass(string $message): string
720+
{
721+
return preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', static function ($m) {
722+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
723+
}, $message);
724+
}
715725
}

src/Symfony/Component/ErrorHandler/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"psr/log": "~1.0",
21-
"symfony/error-renderer": "^4.4|^5.0"
20+
"psr/log": "~1.0"
2221
},
2322
"conflict": {
2423
"symfony/http-kernel": "<3.4"

0 commit comments

Comments
 (0)