From 03e18661513bff11f2803d8a4534cc5cef8513ff Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 8 Sep 2025 11:19:43 +0200 Subject: [PATCH] PHP 8.5 | Fix another runtime deprecation notice This fixes yet another "Using null as an array offset" deprecation notice on PHP 8.5. This one only occurred on PHPCS 4.0, not on 3.x. The tests for this fix have been pulled in 1225 (to safeguard that the issue doesn't exist in 3.x) and merged up into the 4.x branch. Note: as the `if` condition was pretty complex, I've done a small refactor to make the code more readable and understandable. --- src/Tokenizers/PHP.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index dde8677256..089d267755 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -2139,15 +2139,25 @@ protected function tokenize($string) continue; } - if (($tokenType !== T_CALLABLE - && isset($lastRelevantNonEmpty) === false) - || ($lastRelevantNonEmpty === T_ARRAY - && $tokenType === '(') - || (isset(Tokens::NAME_TOKENS[$lastRelevantNonEmpty]) === true - && ($tokenType === T_DOUBLE_COLON - || $tokenType === '(' - || $tokenType === ':')) - ) { + $isInlineThen = false; + if (isset($lastRelevantNonEmpty) === false && $tokenType !== T_CALLABLE) { + // Can be anything, but is definitely not a type declaration. + $isInlineThen = true; + } else if (isset($lastRelevantNonEmpty) === true) { + if ($lastRelevantNonEmpty === T_ARRAY && $tokenType === '(') { + // Array declaration in ternary then. + $isInlineThen = true; + } else if (isset(Tokens::NAME_TOKENS[$lastRelevantNonEmpty]) === true + && ($tokenType === T_DOUBLE_COLON + || $tokenType === '(' + || $tokenType === ':') + ) { + // Constant access, function call, static class member access in ternary then. + $isInlineThen = true; + } + } + + if ($isInlineThen === true) { if (PHP_CODESNIFFER_VERBOSITY > 1) { StatusWriter::write("* token $stackPtr changed from ? to T_INLINE_THEN", 2); }