PHP 8.5 | Fix runtime "Using null as an array offset" deprecations #1215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
PHP 8.5 | File::getMemberProperties(): fix "Using null as an array offset" deprecation
If a variable in the global scope is passed to
File::getMemberProperties()
, the token may not have any "conditions".This would result in
array_keys()
returning an empty array, which will causearray_pop()
to returnnull
, leading to the deprecation notice.Fixed now via some extra defensive coding.
This change is already covered via the existing tests.
PHP 8.5 | Tokenizer/PHP: fix "Using null as an array offset" deprecation
If an attribute is unclosed (missing the closing
]
bracket), thePHP::findCloser()
returnsnull
, which will lead to the PHP 8.5 deprecation notice.This can only occur during live coding or when a file has a parse error, but PHPCS should handle that situation gracefully.
Fixed now.
This change is already covered via the existing tests.
PHP 8.5 | Tokenizer/PHP: temporarily silence "Using null as an array offset" deprecation
When running the
NullsafeObjectOperatorTest
, the "Using null as an array offset" deprecation gets triggered in the tokenizer layer handling re-tokenization toT_NULLABLE
and/orT_INLINE_THEN
.This should only be possible if the below code at the top of the loop would result in
$tokenType
beingnull
, which shouldn't be possible....PHP_CodeSniffer/src/Tokenizers/PHP.php
Lines 2254 to 2258 in f1c9394
With this conundrum in mind, I'm electing to (temporarily) silence the deprecation notice for now until there is more time to investigate in more depth.
Suggested changelog entry
Fixed: PHP 8.5 runtime "Using null as an array offset" deprecations
Related issues/external references
Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists