From 699f400784998479c2ca5a287cf8de6a82d6ab9d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 22 Feb 2024 06:38:24 -0500 Subject: [PATCH] [ErrorHandler] Fix parsing messages that contain anonymous classes on PHP >= 8.3.3 --- .../Component/ErrorHandler/DebugClassLoader.php | 2 +- src/Symfony/Component/ErrorHandler/ErrorHandler.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index d5e81052ce6f3..5db2f30a1c7b4 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -1097,7 +1097,7 @@ private function fixReturnStatements(\ReflectionMethod $method, string $returnTy $braces = 0; for (; $i < $end; ++$i) { if (!$inClosure) { - $inClosure = str_contains($code[$i], 'function ('); + $inClosure = false !== strpos($code[$i], 'function ('); } if ($inClosure) { diff --git a/src/Symfony/Component/ErrorHandler/ErrorHandler.php b/src/Symfony/Component/ErrorHandler/ErrorHandler.php index d7b90439a5a5c..28b93c2b158b7 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorHandler.php +++ b/src/Symfony/Component/ErrorHandler/ErrorHandler.php @@ -457,7 +457,7 @@ public function handleError(int $type, string $message, string $file, int $line) return true; } } else { - if (false !== strpos($message, '@anonymous')) { + if (PHP_VERSION_ID < 80303 && false !== strpos($message, '@anonymous')) { $backtrace = debug_backtrace(false, 5); for ($i = 1; isset($backtrace[$i]); ++$i) { @@ -465,8 +465,7 @@ public function handleError(int $type, string $message, string $file, int $line) && ('trigger_error' === $backtrace[$i]['function'] || 'user_error' === $backtrace[$i]['function']) ) { if ($backtrace[$i]['args'][0] !== $message) { - $message = $this->parseAnonymousClass($backtrace[$i]['args'][0]); - $logMessage = $this->levels[$type].': '.$message; + $message = $backtrace[$i]['args'][0]; } break; @@ -474,6 +473,11 @@ public function handleError(int $type, string $message, string $file, int $line) } } + if (false !== strpos($message, "@anonymous\0")) { + $message = $this->parseAnonymousClass($message); + $logMessage = $this->levels[$type].': '.$message; + } + $errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line); if ($throw || $this->tracedErrors & $type) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy