Skip to content

Commit

Permalink
[ErrorHandler] Fix parsing messages that contain anonymous classes on…
Browse files Browse the repository at this point in the history
… PHP >= 8.3.3
  • Loading branch information
nicolas-grekas committed Feb 22, 2024
1 parent d4475c5 commit 90b1d77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,23 +457,27 @@ 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) {
if (isset($backtrace[$i]['function'], $backtrace[$i]['args'][0])
&& ('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;
}
}
}

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) {
Expand Down

0 comments on commit 90b1d77

Please sign in to comment.