Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/FrameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public function buildFromBacktraceFrame(string $file, int $line, array $backtrac
$functionName = $backtraceFrame['function'];
}

// Starting with PHP 8.4 a closure function call is reported as "{closure:filename:line}" instead of just "{closure}", properly strip the prefixes from that format
if (\PHP_VERSION_ID >= 80400 && $functionName !== null && $this->options->getPrefixes()) {
$prefixStrippedFunctionName = preg_replace_callback('/^\{closure:(.*?):(\d+)}$/', function (array $matches) {
return '{closure:' . $this->stripPrefixFromFilePath($this->options, $matches[1]) . ':' . $matches[2] . '}';
}, $functionName);

if ($prefixStrippedFunctionName) {
$functionName = $prefixStrippedFunctionName;
}
}

return new Frame(
$functionName,
$strippedFilePath,
Expand Down
14 changes: 14 additions & 0 deletions tests/FrameBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ public static function buildFromBacktraceFrameDataProvider(): \Generator
],
new Frame("App\\ClassName@anonymous\0/file::test_function", '/file', 10, "App\\ClassName@anonymous\0/path/to/file:85$29e::test_function", '/path/to/file'),
];

if (\PHP_VERSION_ID >= 80400) {
yield [
new Options([
'prefixes' => ['/path/to'],
]),
[
'file' => '/path/to/file',
'line' => 18,
'function' => '{closure:/path/to/file:18}',
],
new Frame('{closure:/file:18}', '/file', 18, null, '/path/to/file'),
];
}
}

/**
Expand Down