Skip to content

Commit 90b1d77

Browse files
[ErrorHandler] Fix parsing messages that contain anonymous classes on PHP >= 8.3.3
1 parent d4475c5 commit 90b1d77

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

DebugClassLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ private function fixReturnStatements(\ReflectionMethod $method, string $returnTy
10971097
$braces = 0;
10981098
for (; $i < $end; ++$i) {
10991099
if (!$inClosure) {
1100-
$inClosure = str_contains($code[$i], 'function (');
1100+
$inClosure = false !== strpos($code[$i], 'function (');
11011101
}
11021102

11031103
if ($inClosure) {

ErrorHandler.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,27 @@ public function handleError(int $type, string $message, string $file, int $line)
457457
return true;
458458
}
459459
} else {
460-
if (false !== strpos($message, '@anonymous')) {
460+
if (PHP_VERSION_ID < 80303 && false !== strpos($message, '@anonymous')) {
461461
$backtrace = debug_backtrace(false, 5);
462462

463463
for ($i = 1; isset($backtrace[$i]); ++$i) {
464464
if (isset($backtrace[$i]['function'], $backtrace[$i]['args'][0])
465465
&& ('trigger_error' === $backtrace[$i]['function'] || 'user_error' === $backtrace[$i]['function'])
466466
) {
467467
if ($backtrace[$i]['args'][0] !== $message) {
468-
$message = $this->parseAnonymousClass($backtrace[$i]['args'][0]);
469-
$logMessage = $this->levels[$type].': '.$message;
468+
$message = $backtrace[$i]['args'][0];
470469
}
471470

472471
break;
473472
}
474473
}
475474
}
476475

476+
if (false !== strpos($message, "@anonymous\0")) {
477+
$message = $this->parseAnonymousClass($message);
478+
$logMessage = $this->levels[$type].': '.$message;
479+
}
480+
477481
$errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
478482

479483
if ($throw || $this->tracedErrors & $type) {

0 commit comments

Comments
 (0)