Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,7 @@ protected function tokenize(string $code)
&& isset(Tokens::EMPTY_TOKENS[$tokenType]) === false
) {
// Found the previous non-empty token.
if ($tokenType === ':' || $tokenType === ',' || $tokenType === T_ATTRIBUTE_END) {
if ($tokenType === ':' || $tokenType === ',' || $tokenType === '(' || $tokenType === T_ATTRIBUTE_END) {
$newToken['code'] = T_NULLABLE;
$newToken['type'] = 'T_NULLABLE';

Expand Down
12 changes: 12 additions & 0 deletions tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ abstract class Nullable

/* testNullableAbstractOnly */
abstract ?string $prop5 { get; }

public int $prop6 {
/* testPropertyHookParamTypeNullableInt */
set(?int $value) {
$this->prop6 = $value ?? 0;
}
}

public string $prop7 {
/* testShortPropertyHookParamTypeNullableString */
set(?string $value) => $value ?? '';
}
}

$closure = function (
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static function dataNullable()
'property declaration, final, no visibility' => ['/* testNullableFinalOnly */'],
'property declaration, abstract, no visibility' => ['/* testNullableAbstractOnly */'],

'property hook param type, nullable int' => ['/* testPropertyHookParamTypeNullableInt */'],
'short property hook param type, nullable string' => ['/* testShortPropertyHookParamTypeNullableString */'],

'closure param type, nullable int' => ['/* testClosureParamTypeNullableInt */'],
'closure param type, nullable callable' => ['/* testClosureParamTypeNullableCallable */'],
'closure param type, nullable string with comment, issue #1216' => ['/* testClosureParamTypeNullableStringWithAttributeAndSlashComment */'],
Expand Down
Loading