Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Sep 5, 2025

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 cause array_pop() to return null, 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), the PHP::findCloser() returns null, 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 to T_NULLABLE and/or T_INLINE_THEN.

This should only be possible if the below code at the top of the loop would result in $tokenType being null, which shouldn't be possible....

if (is_array($tokens[$i]) === true) {
$tokenType = $tokens[$i][0];
} else {
$tokenType = $tokens[$i];
}

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

…fset" 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 cause `array_pop()` to return `null`, leading to the deprecation notice.

Fixed now via some extra defensive coding.

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
If an attribute is unclosed (missing the closing `]` bracket), the `PHP::findCloser()` returns `null`, 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.

Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
…offset" deprecation

When running the `NullsafeObjectOperatorTest`, the "Using null as an array offset" deprecation gets triggered in the tokenizer layer handling re-tokenization to `T_NULLABLE` and/or `T_INLINE_THEN`.

This should only be possible if the below code at the top of the loop would result in `$tokenType` being `null`, which shouldn't be possible....
https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/f1c9394f1724ed45ca42029da330ff5c702af2a9/src/Tokenizers/PHP.php#L2254-L2258

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.

Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant