Skip to content

Commit 62dfe19

Browse files
committed
FIX Handle PHP 8.4 closure string
1 parent c56f8fc commit 62dfe19

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Dev/Deprecation.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ private static function get_called_from_trace(array $backtrace, int $level): arr
169169
{
170170
$newLevel = $level;
171171
// handle closures inside withSuppressedNotice()
172-
if (Deprecation::$insideNoticeSuppression
173-
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
174-
) {
175-
$newLevel = $newLevel + 2;
172+
if (Deprecation::$insideNoticeSuppression) {
173+
$func = $backtrace[$newLevel]['function'];
174+
// different versions of php have different formats for closures
175+
// php <=8.3 example "SilverStripe\Dev\{closure}"
176+
// php >=8.4 example "{closure:SilverStripe\Dev\Deprecation::noticeWithNoReplacment():464}"
177+
if (str_ends_with($func, '{closure}') || str_starts_with($func, '{closure:')) {
178+
$newLevel = $newLevel + 2;
179+
}
176180
}
177181
// handle call_user_func
178182
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {

0 commit comments

Comments
 (0)