Skip to content

Commit 1a26845

Browse files
committed
PHP 8.5 | Tokenizer/PHP: fix "Using null as an array offset" deprecation
If a comment is on its own line, the new line token is merged into the comment token, and the new line is skipped by setting it to `null`. Where the next line contains incomplete, or invalid, code which ends in an nullsafe operator (for example `$obj?`), the tokenizer will step backwards until it finds the next non-empty line. The skipped new line token should be skipped during this parsing. This can only occur during live coding or when a file has a parse error, but PHPCS should handle that situation gracefully. Fixed now. Fixes #1216. This change is already covered via the existing tests. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
1 parent 379692d commit 1a26845

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,9 @@ protected function tokenize($string)
22552255
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
22562256
if (is_array($tokens[$i]) === true) {
22572257
$tokenType = $tokens[$i][0];
2258+
} else if ($tokens[$i] === null) {
2259+
// Ignore skipped tokens.
2260+
continue;
22582261
} else {
22592262
$tokenType = $tokens[$i];
22602263
}

0 commit comments

Comments
 (0)