File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -646,6 +646,25 @@ protected function tokenize($string)
646646 }//end if
647647 }//end if
648648
649+ /*
650+ PHP 8.1 introduced two dedicated tokens for the & character.
651+ Retokenizing both of these to T_BITWISE_AND, which is the
652+ token PHPCS already tokenized them as.
653+ */
654+
655+ if ($ tokenIsArray === true
656+ && ($ token [0 ] === T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
657+ || $ token [0 ] === T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG )
658+ ) {
659+ $ finalTokens [$ newStackPtr ] = [
660+ 'code ' => T_BITWISE_AND ,
661+ 'type ' => 'T_BITWISE_AND ' ,
662+ 'content ' => $ token [1 ],
663+ ];
664+ $ newStackPtr ++;
665+ continue ;
666+ }
667+
649668 /*
650669 If this is a double quoted string, PHP will tokenize the whole
651670 thing which causes problems with the scope map when braces are
@@ -1667,7 +1686,8 @@ protected function tokenize($string)
16671686 if ($ token [0 ] === T_FUNCTION ) {
16681687 for ($ x = ($ stackPtr + 1 ); $ x < $ numTokens ; $ x ++) {
16691688 if (is_array ($ tokens [$ x ]) === false
1670- || isset (Util \Tokens::$ emptyTokens [$ tokens [$ x ][0 ]]) === false
1689+ || (isset (Util \Tokens::$ emptyTokens [$ tokens [$ x ][0 ]]) === false
1690+ && $ tokens [$ x ][1 ] !== '& ' )
16711691 ) {
16721692 // Non-empty content.
16731693 break ;
Original file line number Diff line number Diff line change 154154 define ('T_ATTRIBUTE ' , 'PHPCS_T_ATTRIBUTE ' );
155155}
156156
157+ // Some PHP 8.1 tokens, replicated for lower versions.
158+ if (defined ('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG ' ) === false ) {
159+ define ('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG ' , 'PHPCS_T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG ' );
160+ }
161+
162+ if (defined ('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG ' ) === false ) {
163+ define ('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG ' , 'PHPCS_T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG ' );
164+ }
165+
157166// Tokens used for parsing doc blocks.
158167define ('T_DOC_COMMENT_STAR ' , 'PHPCS_T_DOC_COMMENT_STAR ' );
159168define ('T_DOC_COMMENT_WHITESPACE ' , 'PHPCS_T_DOC_COMMENT_WHITESPACE ' );
You can’t perform that action at this time.
0 commit comments