Repository navigation
Keep the analysed PHP version as the floor of a PHP_VERSION_ID < X guard #6746
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
staabm
merged 2 commits into
phpstan:2.3.x
from
HawkForge:fix/php-version-id-narrowing-below-configured
Oct 24, 2026
+324
−75
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/PHPStan/Rules/Classes/InvalidPromotedPropertiesRulePhpVersionRangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Classes; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<InvalidPromotedPropertiesRule> | ||
| */ | ||
| class InvalidPromotedPropertiesRulePhpVersionRangeTest extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new InvalidPromotedPropertiesRule(); | ||
| } | ||
|
|
||
| #[RequiresPhp('>= 8.0.0')] | ||
| public function testBug15425(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-15425-range.php'], [ | ||
| [ | ||
| 'Promoted properties are supported only on PHP 8.0 and later.', | ||
| 10, | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return [ | ||
| __DIR__ . '/invalidPromotedPropertiesPhpVersionRange.neon', | ||
| ]; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/PHPStan/Rules/Classes/ReadOnlyClassRulePhp81Test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Classes; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<ReadOnlyClassRule> | ||
| */ | ||
| class ReadOnlyClassRulePhp81Test extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new ReadOnlyClassRule(); | ||
| } | ||
|
|
||
| #[RequiresPhp('>= 8.2.0')] | ||
| public function testBug15425(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-15425-readonly.php'], [ | ||
| [ | ||
| 'Readonly classes are supported only on PHP 8.2 and later.', | ||
| 8, | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return [ | ||
| __DIR__ . '/readOnlyClassPhp81.neon', | ||
| ]; | ||
| } | ||
|
|
||
| } |
5 changes: 5 additions & 0 deletions
5
tests/PHPStan/Rules/Classes/data/bug-15425-composer/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "require": { | ||
| "php": "<8.4" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425Range; | ||
|
|
||
| if (PHP_VERSION_ID < 80300) { | ||
| final class Foo | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php // lint >= 8.2 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425Readonly; | ||
|
|
||
| if (PHP_VERSION_ID < 80400) { | ||
| final readonly class Foo | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425; | ||
|
|
||
| if (PHP_VERSION_ID < 80400) { | ||
|
staabm marked this conversation as resolved.
|
||
| final class Foo | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (PHP_VERSION_ID < 80000) { | ||
| final class Bar | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
tests/PHPStan/Rules/Classes/invalidPromotedPropertiesPhpVersionRange.neon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
|
staabm marked this conversation as resolved.
|
||
| # composer.json "php": "<8.4" gives a version range without a lower bound | ||
| composerAutoloaderProjectPaths: | ||
| - %rootDir%/tests/PHPStan/Rules/Classes/data/bug-15425-composer | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| parameters: | ||
| phpVersion: 80100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the composer.json files? I think the
PHP_VERSION_ID < 80400should be enough.does the expected behaviour only reproduce with a composer.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, the issue itself only needs
PHP_VERSION_ID < 80400, that one istestBug15425inInvalidPromotedPropertiesRuleTestand has no composer.json. This composer.json is only for thegetConfiguredPhpVersionRange() === nullcheck Sander found: a constraint like"php": "<8.4"has no lower bound, and a NEONphpVersionrange cant do that (min can not be below 7.1). Without the check that test fails, with it the issue test is unaffected.