|
21 | 21 | use Symfony\Component\ErrorHandler\FatalErrorHandler\FatalErrorHandlerInterface;
|
22 | 22 | use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
|
23 | 23 | use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
|
24 |
| -use Symfony\Component\ErrorRenderer\Exception\FlattenException; |
25 | 24 |
|
26 | 25 | /**
|
27 | 26 | * A generic ErrorHandler for the PHP engine.
|
@@ -414,7 +413,7 @@ public function handleError($type, $message, $file, $line)
|
414 | 413 | }
|
415 | 414 |
|
416 | 415 | if (false !== strpos($message, "class@anonymous\0")) {
|
417 |
| - $logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage(); |
| 416 | + $logMessage = $this->parseAnonymousClass($message); |
418 | 417 | } else {
|
419 | 418 | $logMessage = $this->levels[$type].': '.$message;
|
420 | 419 | }
|
@@ -539,7 +538,7 @@ public function handleException($exception, array $error = null)
|
539 | 538 |
|
540 | 539 | if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
|
541 | 540 | if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) {
|
542 |
| - $message = (new FlattenException())->setMessage($message)->getMessage(); |
| 541 | + $message = $this->parseAnonymousClass($message); |
543 | 542 | }
|
544 | 543 | if ($exception instanceof FatalErrorException) {
|
545 | 544 | if ($exception instanceof FatalThrowableError) {
|
@@ -712,4 +711,15 @@ private function cleanTrace($backtrace, $type, $file, $line, $throw)
|
712 | 711 |
|
713 | 712 | return $lightTrace;
|
714 | 713 | }
|
| 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 | + } |
715 | 725 | }
|
0 commit comments