Skip to content

Commit 288a2a9

Browse files
authored
Merge pull request #1215 from PHPCSStandards/php-8.5/fix-null-as-array-offset-deprecation
PHP 8.5 | Fix runtime "Using null as an array offset" deprecations
2 parents d9b3e66 + 6b82a86 commit 288a2a9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/Files/File.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,10 @@ public function getMemberProperties($stackPtr)
18761876
throw new RuntimeException('$stackPtr must be of type T_VARIABLE');
18771877
}
18781878

1879+
if (empty($this->tokens[$stackPtr]['conditions']) === true) {
1880+
throw new RuntimeException('$stackPtr is not a class member var');
1881+
}
1882+
18791883
$conditions = array_keys($this->tokens[$stackPtr]['conditions']);
18801884
$ptr = array_pop($conditions);
18811885
if (isset($this->tokens[$ptr]) === false

src/Tokenizers/PHP.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,16 +1468,18 @@ protected function tokenize($string)
14681468
$newToken['type'] = 'T_ATTRIBUTE';
14691469
$newToken['content'] = '#[';
14701470
$finalTokens[$newStackPtr] = $newToken;
1471+
$newStackPtr++;
14711472

1472-
$tokens[$bracketCloser] = [];
1473-
$tokens[$bracketCloser][0] = T_ATTRIBUTE_END;
1474-
$tokens[$bracketCloser][1] = ']';
1473+
if ($bracketCloser !== null) {
1474+
$tokens[$bracketCloser] = [];
1475+
$tokens[$bracketCloser][0] = T_ATTRIBUTE_END;
1476+
$tokens[$bracketCloser][1] = ']';
14751477

1476-
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1477-
echo "\t\t* token $bracketCloser changed from T_CLOSE_SQUARE_BRACKET to T_ATTRIBUTE_END".PHP_EOL;
1478+
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1479+
echo "\t\t* token $bracketCloser changed from T_CLOSE_SQUARE_BRACKET to T_ATTRIBUTE_END".PHP_EOL;
1480+
}
14781481
}
14791482

1480-
$newStackPtr++;
14811483
continue;
14821484
}//end if
14831485

@@ -2266,7 +2268,7 @@ protected function tokenize($string)
22662268
}
22672269

22682270
if ($prevNonEmpty === null
2269-
&& isset(Tokens::$emptyTokens[$tokenType]) === false
2271+
&& @isset(Tokens::$emptyTokens[$tokenType]) === false
22702272
) {
22712273
// Found the previous non-empty token.
22722274
if ($tokenType === ':' || $tokenType === ',' || $tokenType === T_ATTRIBUTE_END) {
@@ -2285,8 +2287,8 @@ protected function tokenize($string)
22852287

22862288
if ($tokenType === T_FUNCTION
22872289
|| $tokenType === T_FN
2288-
|| isset(Tokens::$methodPrefixes[$tokenType]) === true
2289-
|| isset(Tokens::$scopeModifiers[$tokenType]) === true
2290+
|| @isset(Tokens::$methodPrefixes[$tokenType]) === true
2291+
|| @isset(Tokens::$scopeModifiers[$tokenType]) === true
22902292
|| $tokenType === T_VAR
22912293
|| $tokenType === T_READONLY
22922294
) {
@@ -2309,7 +2311,7 @@ protected function tokenize($string)
23092311
break;
23102312
}
23112313

2312-
if (isset(Tokens::$emptyTokens[$tokenType]) === false) {
2314+
if (@isset(Tokens::$emptyTokens[$tokenType]) === false) {
23132315
$lastSeenNonEmpty = $tokenType;
23142316
}
23152317
}//end for

0 commit comments

Comments
 (0)