Skip to content

PHP 8.4 | Tokenizer/PHP: fix union/intersection/DNF type tokenization with final properties #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
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
3 changes: 2 additions & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3379,7 +3379,8 @@ protected function processAdditional()
&& (isset(Tokens::$scopeModifiers[$this->tokens[$x]['code']]) === true
|| $this->tokens[$x]['code'] === T_VAR
|| $this->tokens[$x]['code'] === T_STATIC
|| $this->tokens[$x]['code'] === T_READONLY)
|| $this->tokens[$x]['code'] === T_READONLY
|| $this->tokens[$x]['code'] === T_FINAL)
) {
// This will also confirm constructor property promotion parameters, but that's fine.
$confirmed = true;
Expand Down
9 changes: 9 additions & 0 deletions tests/Core/Tokenizers/PHP/BitwiseOrTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ class TypeUnion
/* testTypeUnionPropertyWithOnlyStaticKeyword */
static Foo|Bar $obj;

/* testTypeUnionWithPHP84FinalKeyword */
final int|string $finalKeywordA;

/* testTypeUnionWithPHP84FinalKeywordFirst */
final private float|null $finalKeywordB;

/* testTypeUnionWithPHP84FinalKeywordAndFQN */
final \MyClass|false $finalKeywordC;

public function paramTypes(
/* testTypeUnionParam1 */
int|float $paramA /* testBitwiseOrParamDefaultValue */ = CONSTANT_A | CONSTANT_B,
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Tokenizers/PHP/BitwiseOrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public static function dataTypeUnion()
'type for readonly property, reversed modifier order' => ['/* testTypeUnionPropertyWithReadOnlyKeywordFirst */'],
'type for readonly property, no visibility' => ['/* testTypeUnionPropertyWithOnlyReadOnlyKeyword */'],
'type for static property, no visibility' => ['/* testTypeUnionPropertyWithOnlyStaticKeyword */'],
'type for final property, no visibility' => ['/* testTypeUnionWithPHP84FinalKeyword */'],
'type for final property, reversed modifier order' => ['/* testTypeUnionWithPHP84FinalKeywordFirst */'],
'type for final property, no visibility, FQN type' => ['/* testTypeUnionWithPHP84FinalKeywordAndFQN */'],
'type for method parameter' => ['/* testTypeUnionParam1 */'],
'type for method parameter, first in multi-union' => ['/* testTypeUnionParam2 */'],
'type for method parameter, last in multi-union' => ['/* testTypeUnionParam3 */'],
Expand Down
6 changes: 6 additions & 0 deletions tests/Core/Tokenizers/PHP/DNFTypesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ abstract class DNFTypes {
/* testDNFTypePropertyWithOnlyStaticKeyword */
static (A&B&C)|true $onlyStaticModified;

/* testDNFTypeWithPHP84FinalKeyword */
final (className&InterfaceName)|false $finalKeywordA;

/* testDNFTypeWithPHP84FinalKeywordAndStatic */
final static (\className&\InterfaceName)|false $finalKeywordB;

public function paramTypes(
/* testDNFTypeParam1WithAttribute */
#[MyAttribute]
Expand Down
8 changes: 7 additions & 1 deletion tests/Core/Tokenizers/PHP/DNFTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ public static function dataDNFTypeParentheses()
'OO property type: multi-dnf fully qualified classes' => [
'testMarker' => '/* testDNFTypePropertyMultiFullyQualified */',
],

'OO property type: multi-dnf with readonly keyword 1' => [
'testMarker' => '/* testDNFTypePropertyWithReadOnlyKeyword1 */',
],
Expand All @@ -445,6 +444,13 @@ public static function dataDNFTypeParentheses()
'OO property type: with only static keyword' => [
'testMarker' => '/* testDNFTypePropertyWithOnlyStaticKeyword */',
],
'OO property type: with only final keyword' => [
'testMarker' => '/* testDNFTypeWithPHP84FinalKeyword */',
],
'OO property type: with final and static keyword' => [
'testMarker' => '/* testDNFTypeWithPHP84FinalKeywordAndStatic */',
],

'OO method param type: first param' => [
'testMarker' => '/* testDNFTypeParam1WithAttribute */',
],
Expand Down
6 changes: 6 additions & 0 deletions tests/Core/Tokenizers/PHP/TypeIntersectionTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class TypeIntersection
/* testTypeIntersectionPropertyWithStaticKeyword */
static Foo&Bar $obj;

/* testTypeIntersectionWithPHP84FinalKeyword */
final className&InterfaceName $finalKeywordA;

/* testTypeIntersectionWithPHP84FinalKeywordFirst */
final private \className&InterfaceName $finalKeywordB;

public function paramTypes(
/* testTypeIntersectionParam1 */
Foo&Bar $paramA /* testBitwiseAndParamDefaultValue */ = CONSTANT_A & CONSTANT_B,
Expand Down
2 changes: 2 additions & 0 deletions tests/Core/Tokenizers/PHP/TypeIntersectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public static function dataTypeIntersection()
'type for property using fully qualified names' => ['/* testTypeIntersectionPropertyFullyQualified */'],
'type for readonly property' => ['/* testTypeIntersectionPropertyWithReadOnlyKeyword */'],
'type for static readonly property' => ['/* testTypeIntersectionPropertyWithStaticKeyword */'],
'type for final property' => ['/* testTypeIntersectionWithPHP84FinalKeyword */'],
'type for final property reversed modifier order' => ['/* testTypeIntersectionWithPHP84FinalKeywordFirst */'],
'type for method parameter' => ['/* testTypeIntersectionParam1 */'],
'type for method parameter, first in multi-intersect' => ['/* testTypeIntersectionParam2 */'],
'type for method parameter, last in multi-intersect' => ['/* testTypeIntersectionParam3 */'],
Expand Down