Skip to content

Commit 8112f56

Browse files
committed
PHP 8.0 | Tokenizer/PHP: array return type keyword to T_STRING vs PHP8 union types
`array` keywords used as return types in PHP 8 union types would only be correctly changed to `T_STRING` if they were the first type in the union. Fixed now. Includes adding `T_STATIC` to the array of allowed tokens. While previously it wasn't an issue that the token was not included in the array, it is necessary for the token to be there to support union types. This change will be tested via the union type related tests for the `File::getMethodProperties()` method.
1 parent 63c2b22 commit 8112f56

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Tokenizers/PHP.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ function return types. We want to keep the parenthesis map clean,
14751475
T_SELF => T_SELF,
14761476
T_PARENT => T_PARENT,
14771477
T_NAMESPACE => T_NAMESPACE,
1478+
T_STATIC => T_STATIC,
14781479
T_NS_SEPARATOR => T_NS_SEPARATOR,
14791480
];
14801481

@@ -1509,12 +1510,14 @@ function return types. We want to keep the parenthesis map clean,
15091510
}//end for
15101511

15111512
// Any T_ARRAY tokens we find between here and the next
1512-
// token that can't be part of the return type need to be
1513+
// token that can't be part of the return type, need to be
15131514
// converted to T_STRING tokens.
15141515
for ($x; $x < $numTokens; $x++) {
1515-
if (is_array($tokens[$x]) === false || isset($allowed[$tokens[$x][0]]) === false) {
1516+
if ((is_array($tokens[$x]) === false && $tokens[$x] !== '|')
1517+
|| (is_array($tokens[$x]) === true && isset($allowed[$tokens[$x][0]]) === false)
1518+
) {
15161519
break;
1517-
} else if ($tokens[$x][0] === T_ARRAY) {
1520+
} else if (is_array($tokens[$x]) === true && $tokens[$x][0] === T_ARRAY) {
15181521
$tokens[$x][0] = T_STRING;
15191522

15201523
if (PHP_CODESNIFFER_VERBOSITY > 1) {

0 commit comments

Comments
 (0)