From e65af1b1259c2531e0256dc2f3af48a8d6a80da9 Mon Sep 17 00:00:00 2001 From: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com> Date: Mon, 15 Jun 2026 15:48:14 +0000 Subject: [PATCH] RequiredPhpVersionVisitor: report promoted properties as requiring PHP 8.0 - Detect constructor property promotion (a `Node\Param` carrying any modifier flag) and require PHP 8.0, alongside the existing readonly-promotion (8.1) and asymmetric-visibility (8.4) checks on `Node\Param`. - Add `// lint >= 8.0` comments to the 24 existing fixtures that use promoted properties without one, preserving line numbers for line-sensitive assertions. - Add `testDetectedVersion` cases for public/protected/private promoted properties and a negative case for a non-promoted parameter. --- build/PHPStan/Build/RequiredPhpVersionVisitor.php | 4 ++++ tests/PHPStan/Analyser/data/bug-7116.php | 4 ++-- tests/PHPStan/Analyser/nsrt/assert-constructor.php | 2 +- tests/PHPStan/Analyser/nsrt/assert-this.php | 2 +- tests/PHPStan/Analyser/nsrt/bug-13851.php | 4 ++-- tests/PHPStan/Analyser/nsrt/bug-14645.php | 2 +- tests/PHPStan/Analyser/nsrt/bug-6633.php | 4 ++-- tests/PHPStan/Analyser/nsrt/bug-8008.php | 2 +- tests/PHPStan/Analyser/nsrt/bug-9455.php | 2 +- tests/PHPStan/Build/RequiredPhpVersionCommentTest.php | 4 ++++ .../Rules/Classes/data/instantiation-promoted-properties.php | 2 +- .../Rules/Classes/data/invalid-promoted-properties.php | 2 +- tests/PHPStan/Rules/Functions/data/bug-10298.php | 4 ++-- tests/PHPStan/Rules/Functions/data/bug-10732.php | 2 +- tests/PHPStan/Rules/Functions/data/bug-12317.php | 4 ++-- tests/PHPStan/Rules/Functions/data/bug-12499.php | 2 +- tests/PHPStan/Rules/Functions/data/bug-6633.php | 4 ++-- tests/PHPStan/Rules/Functions/data/param-attributes.php | 2 +- tests/PHPStan/Rules/Methods/data/bug-11067.php | 4 ++-- tests/PHPStan/Rules/Methods/data/bug-13511.php | 2 +- tests/PHPStan/Rules/Methods/data/bug-13993.php | 2 +- tests/PHPStan/Rules/Methods/data/bug-6353.php | 2 +- tests/PHPStan/Rules/Methods/data/bug-7662.php | 4 ++-- tests/PHPStan/Rules/Methods/data/bug-9494.php | 2 +- tests/PHPStan/Rules/Methods/data/bug-9766.php | 2 +- .../Rules/Methods/data/reflection-class-issue-8679.php | 2 +- 26 files changed, 40 insertions(+), 32 deletions(-) diff --git a/build/PHPStan/Build/RequiredPhpVersionVisitor.php b/build/PHPStan/Build/RequiredPhpVersionVisitor.php index 9af2e885a4a..3ba7ed05635 100644 --- a/build/PHPStan/Build/RequiredPhpVersionVisitor.php +++ b/build/PHPStan/Build/RequiredPhpVersionVisitor.php @@ -88,6 +88,10 @@ public function enterNode(Node $node): ?Node $this->require(self::PHP_8_1, 'readonly properties', $node); } + if ($node instanceof Node\Param && $node->flags !== 0) { + $this->require(self::PHP_8_0, 'promoted properties', $node); + } + if ($node instanceof Node\Param && ($node->flags & Modifiers::READONLY) !== 0) { $this->require(self::PHP_8_1, 'readonly promoted properties', $node); } diff --git a/tests/PHPStan/Analyser/data/bug-7116.php b/tests/PHPStan/Analyser/data/bug-7116.php index c25688f2bbc..c0dcf33a70b 100644 --- a/tests/PHPStan/Analyser/data/bug-7116.php +++ b/tests/PHPStan/Analyser/data/bug-7116.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug7116; #[\Attribute(\Attribute::TARGET_CLASS)] diff --git a/tests/PHPStan/Analyser/nsrt/assert-constructor.php b/tests/PHPStan/Analyser/nsrt/assert-constructor.php index 2d133d8c6c1..fe70ef56d35 100644 --- a/tests/PHPStan/Analyser/nsrt/assert-constructor.php +++ b/tests/PHPStan/Analyser/nsrt/assert-constructor.php @@ -1,4 +1,4 @@ -= 8.0 namespace AssertConstructor; diff --git a/tests/PHPStan/Analyser/nsrt/assert-this.php b/tests/PHPStan/Analyser/nsrt/assert-this.php index 4b29fa697c4..6a31e1578e2 100644 --- a/tests/PHPStan/Analyser/nsrt/assert-this.php +++ b/tests/PHPStan/Analyser/nsrt/assert-this.php @@ -1,4 +1,4 @@ -= 8.0 namespace AssertThis; diff --git a/tests/PHPStan/Analyser/nsrt/bug-13851.php b/tests/PHPStan/Analyser/nsrt/bug-13851.php index 74480f368ae..63358ad4d29 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-13851.php +++ b/tests/PHPStan/Analyser/nsrt/bug-13851.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types=1); namespace Bug13851; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-14645.php b/tests/PHPStan/Analyser/nsrt/bug-14645.php index 459fcedb793..c9f99943480 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-14645.php +++ b/tests/PHPStan/Analyser/nsrt/bug-14645.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug14645; diff --git a/tests/PHPStan/Analyser/nsrt/bug-6633.php b/tests/PHPStan/Analyser/nsrt/bug-6633.php index 3689f53ee9e..b5c6daf9597 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-6633.php +++ b/tests/PHPStan/Analyser/nsrt/bug-6633.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug6633; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-8008.php b/tests/PHPStan/Analyser/nsrt/bug-8008.php index d3e8ae63d40..e3c238e6e96 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-8008.php +++ b/tests/PHPStan/Analyser/nsrt/bug-8008.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug8008; diff --git a/tests/PHPStan/Analyser/nsrt/bug-9455.php b/tests/PHPStan/Analyser/nsrt/bug-9455.php index b3688b8b91c..d14ecd969fd 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-9455.php +++ b/tests/PHPStan/Analyser/nsrt/bug-9455.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9455; diff --git a/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php b/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php index 9adde3a4c36..16a8eb2684f 100644 --- a/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php +++ b/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php @@ -122,6 +122,10 @@ public static function dataDetectedVersion(): iterable yield 'mixed property type' => [' [' [' [' [' [' [' [' [' ['= 8.0 namespace InstantiationPromotedProperties; diff --git a/tests/PHPStan/Rules/Classes/data/invalid-promoted-properties.php b/tests/PHPStan/Rules/Classes/data/invalid-promoted-properties.php index b28c29a53ea..aa027e8daf5 100644 --- a/tests/PHPStan/Rules/Classes/data/invalid-promoted-properties.php +++ b/tests/PHPStan/Rules/Classes/data/invalid-promoted-properties.php @@ -1,4 +1,4 @@ -= 8.0 namespace InvalidPromotedProperties; diff --git a/tests/PHPStan/Rules/Functions/data/bug-10298.php b/tests/PHPStan/Rules/Functions/data/bug-10298.php index dfbfa7979e7..4cc2f1b1fff 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-10298.php +++ b/tests/PHPStan/Rules/Functions/data/bug-10298.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug10298; #[\Attribute(\Attribute::TARGET_PROPERTY)] diff --git a/tests/PHPStan/Rules/Functions/data/bug-10732.php b/tests/PHPStan/Rules/Functions/data/bug-10732.php index daabd2c88a2..9d4f3bd584e 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-10732.php +++ b/tests/PHPStan/Rules/Functions/data/bug-10732.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug10732; diff --git a/tests/PHPStan/Rules/Functions/data/bug-12317.php b/tests/PHPStan/Rules/Functions/data/bug-12317.php index 2443fefc094..53aaed158af 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-12317.php +++ b/tests/PHPStan/Rules/Functions/data/bug-12317.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug12317; class Uuid { diff --git a/tests/PHPStan/Rules/Functions/data/bug-12499.php b/tests/PHPStan/Rules/Functions/data/bug-12499.php index 1322e06e4f5..7dea47dfc9e 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-12499.php +++ b/tests/PHPStan/Rules/Functions/data/bug-12499.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug12499; diff --git a/tests/PHPStan/Rules/Functions/data/bug-6633.php b/tests/PHPStan/Rules/Functions/data/bug-6633.php index 31bc3cf7d89..989c6a8f850 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-6633.php +++ b/tests/PHPStan/Rules/Functions/data/bug-6633.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug6633\Rule; class CreateServiceSolrData diff --git a/tests/PHPStan/Rules/Functions/data/param-attributes.php b/tests/PHPStan/Rules/Functions/data/param-attributes.php index 39231f293e2..9c2207c4b31 100644 --- a/tests/PHPStan/Rules/Functions/data/param-attributes.php +++ b/tests/PHPStan/Rules/Functions/data/param-attributes.php @@ -1,4 +1,4 @@ -= 8.0 namespace ParamAttributes; diff --git a/tests/PHPStan/Rules/Methods/data/bug-11067.php b/tests/PHPStan/Rules/Methods/data/bug-11067.php index 7245f5feca1..2ff8febed27 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-11067.php +++ b/tests/PHPStan/Rules/Methods/data/bug-11067.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug11067; interface BuilderInterface diff --git a/tests/PHPStan/Rules/Methods/data/bug-13511.php b/tests/PHPStan/Rules/Methods/data/bug-13511.php index cf7efde5be2..a889aaefb40 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-13511.php +++ b/tests/PHPStan/Rules/Methods/data/bug-13511.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug13511; diff --git a/tests/PHPStan/Rules/Methods/data/bug-13993.php b/tests/PHPStan/Rules/Methods/data/bug-13993.php index d9847a96861..78b3222c5d1 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-13993.php +++ b/tests/PHPStan/Rules/Methods/data/bug-13993.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug13993; diff --git a/tests/PHPStan/Rules/Methods/data/bug-6353.php b/tests/PHPStan/Rules/Methods/data/bug-6353.php index f9542a4c159..ef4d33a7428 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-6353.php +++ b/tests/PHPStan/Rules/Methods/data/bug-6353.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug6353; diff --git a/tests/PHPStan/Rules/Methods/data/bug-7662.php b/tests/PHPStan/Rules/Methods/data/bug-7662.php index 826ba3fe845..f9bfe7870f8 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-7662.php +++ b/tests/PHPStan/Rules/Methods/data/bug-7662.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug7662; class Foo { diff --git a/tests/PHPStan/Rules/Methods/data/bug-9494.php b/tests/PHPStan/Rules/Methods/data/bug-9494.php index 3e9146ab6b9..bd8f5dd56a5 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-9494.php +++ b/tests/PHPStan/Rules/Methods/data/bug-9494.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9494; diff --git a/tests/PHPStan/Rules/Methods/data/bug-9766.php b/tests/PHPStan/Rules/Methods/data/bug-9766.php index 2be59b73dc2..5413ee62f14 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-9766.php +++ b/tests/PHPStan/Rules/Methods/data/bug-9766.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9766; diff --git a/tests/PHPStan/Rules/Methods/data/reflection-class-issue-8679.php b/tests/PHPStan/Rules/Methods/data/reflection-class-issue-8679.php index 32c3937b525..99c5fb27837 100644 --- a/tests/PHPStan/Rules/Methods/data/reflection-class-issue-8679.php +++ b/tests/PHPStan/Rules/Methods/data/reflection-class-issue-8679.php @@ -1,4 +1,4 @@ -= 8.0 namespace ReflectionClassIssue8679;