From cfc0127a84f82091be477c7ecfe86d5e34f5ff85 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 3 Dec 2024 13:54:59 +1300 Subject: [PATCH] FIX Handle PHP 8.4 closure string --- src/Dev/Deprecation.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index 05050c4f193..5251fb04eda 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -169,10 +169,14 @@ private static function get_called_from_trace(array $backtrace, int $level): arr { $newLevel = $level; // handle closures inside withSuppressedNotice() - if (Deprecation::$insideNoticeSuppression - && substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}' - ) { - $newLevel = $newLevel + 2; + if (Deprecation::$insideNoticeSuppression) { + $func = $backtrace[$newLevel]['function']; + // different versions of php have different formats for closures + // php <=8.3 example "SilverStripe\Dev\{closure}" + // php >=8.4 example "{closure:SilverStripe\Dev\Deprecation::noticeWithNoReplacment():464}" + if (str_ends_with($func, '{closure}') || str_starts_with($func, '{closure:')) { + $newLevel = $newLevel + 2; + } } // handle call_user_func if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {