Skip to content

Commit ece4547

Browse files
committed
PHP 8.2 | Tokenizer/PHP: allow for true in union types
Previously, `false` and `null` were already allowed in union types. As of PHP 8.2, `true` has been added to the supported types in PHP and can also be used in union types. Also see: https://3v4l.org/ZpfID This commit adjusts the Tokenizer to correctly retokenize the `T_BITWISE_OR` character to `T_UNION_TYPE` when `true` is included in a union type. Includes unit tests. Refs: * https://wiki.php.net/rfc/true-type
1 parent 2ff6414 commit ece4547

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,7 @@ protected function processAdditional()
29382938
T_PARENT => T_PARENT,
29392939
T_STATIC => T_STATIC,
29402940
T_FALSE => T_FALSE,
2941+
T_TRUE => T_TRUE,
29412942
T_NULL => T_NULL,
29422943
T_NAMESPACE => T_NAMESPACE,
29432944
T_NS_SEPARATOR => T_NS_SEPARATOR,

tests/Core/Tokenizer/BitwiseOrTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ $obj->fn($something | $else);
129129
/* testTypeUnionNonArrowFunctionDeclaration */
130130
function &fn(int|false $something) {}
131131

132+
/* testTypeUnionPHP82TrueFirst */
133+
function trueTypeParam(true|null $param) {}
134+
135+
/* testTypeUnionPHP82TrueMiddle */
136+
function trueTypeReturn($param): array|true|null {}
137+
138+
/* testTypeUnionPHP82TrueLast */
139+
$closure = function ($param): array|true {}
140+
132141
/* testLiveCoding */
133142
// Intentional parse error. This has to be the last test in the file.
134143
return function( type|

tests/Core/Tokenizer/BitwiseOrTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ public function dataTypeUnion()
130130
['/* testTypeUnionArrowParam */'],
131131
['/* testTypeUnionArrowReturnType */'],
132132
['/* testTypeUnionNonArrowFunctionDeclaration */'],
133+
['/* testTypeUnionPHP82TrueFirst */'],
134+
['/* testTypeUnionPHP82TrueMiddle */'],
135+
['/* testTypeUnionPHP82TrueLast */'],
133136
];
134137

135138
}//end dataTypeUnion()

0 commit comments

Comments
 (0)