PHP 8.5 | AbstractArrayDeclarationSniff::getActualArrayKey(): prevent notices about deprecated casts #733
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.
The
AbstractArrayDeclarationSniff::getActualArrayKey()method collects the contents of a subset of tokens and then runseval()on this contents to determine what the array key would be.The code allows for "collecting" type casts tokens as safe for use in the
eval(), however, it did not take into account that there have been a number of changes in the available type casts in PHP over time.Say, the code under scan uses the
(real)type cast in an array key. This type cast was deprecated in PHP 7.4 and has been removed since PHP 8.0.While the code under scan may run on PHP < 8.0 in production, the PHPCS scan might be run on a different PHP version.
eval()and PHPCS catching any such PHP notices and bowing out of scanning the file if/when such notices are encountered.Now, what with PHP 8.5 deprecating another four type casts variants, this issue is now more relevant than ever before.
The changes made in this commit are intended to prevent such notices about deprecated/removed type casts from negatively impacting a PHPCS scan.
Includes tests.