Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.1: fix retokenization of "&" character
In PHP < 8.1, the ampersand was tokenized as a simple token, basically just a plain string "&". As of PHP 8.1, due to the introduction of intersection types, PHP is introducing two new tokens for the ampersand. This PR proposes to "undo" the new PHP 8.1 tokenization of the ampersand in favour of the pre-existing tokenization of the character as `T_BITWISE_AND` as it has been in PHPCS since forever. Includes taking the new tokens into account for the "next token after a function keyword token should be a `T_STRING`" logic. This change is already covered extensively by the tests for the `File::isReference()` method, though that method will need updating for PHP 8.1 intersection types, just like the `File::getMethodParameters()` method will need adjusting too. This PR, in combination with PR 3400, fixes all current test failures on PHP 8.1. We may want to consider adding an extra `'is_reference'` array key index to the token array for these tokens, which would allow the `File::isReference()` method to resolve tokens on PHP 8.1 much more quickly and more easily. We also may want to have a think about whether we want to move to the PHP 8.1 tokenization in PHPCS 4.x. All the same, this PR should not be held back by a decision like that as, for now, it just needs to be fixed for PHPCS 3.x.
- Loading branch information