RequiredPhpVersionVisitor: report promoted properties as requiring PHP 8.0#5882
Merged
staabm merged 1 commit intoJun 15, 2026
Merged
Conversation
…P 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.
staabm
approved these changes
Jun 15, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
RequiredPhpVersionVisitor(the build helper that infers the minimum PHP version a test fixture needs so it can be skipped on older PHP in CI) only flagged readonly promoted properties (PHP 8.1) and asymmetric visibility (PHP 8.4) on constructor parameters. Plain constructor property promotion — itself a PHP 8.0 syntactic feature — was not reported. This is a followup to phpstan/phpstan#14816, phpstan/phpstan#14824 and #5855.Changes
build/PHPStan/Build/RequiredPhpVersionVisitor.php: report aNode\Paramwith any modifier flag ($node->flags !== 0) as requiring PHP 8.0 with reasonpromoted properties. The existing readonly (8.1) and asymmetric-visibility (8.4) checks still win viarequire()taking the highest version.tests/PHPStan/Build/RequiredPhpVersionCommentTest.php: addedtestDetectedVersioncases for public/protected/private promoted properties (all 8.0) and a negative case proving a non-promoted parameter requires nothing.<?php // lint >= 8.0comments to the 24 existing fixtures that use promoted properties without a lint comment, preserving total line counts so line-sensitiveassertType/error assertions are unaffected.Root cause
A promoted property is the only case where a
Node\Paramcarries modifier flags. The visitor checked specific flags (readonly, visibility-set) but never the general "has any modifier" case that signals constructor property promotion, so the base 8.0 requirement was missed.The conceptual axis is "modifiers on a constructor parameter": plain promotion (8.0), readonly promotion (8.1), asymmetric visibility (8.4). With this change all three are covered. Other unrelated PHP 8.0 syntactic features (named arguments, the nullsafe operator,
match, throw-expressions, attributes) are tracked by the sibling issues referenced above and are intentionally left to their own PRs to match the maintainer's one-feature-per-PR workflow.Test
testDetectedVersionnow asserts thatpublic/protected/privatepromoted properties are detected as PHP 8.0 and that a non-promoted parameter is detected asnull. These fail without the fix. The fulltestFixtureHasRequiredLintCommentdata-provider test passes after the 24 fixtures received their// lint >= 8.0comment, and the affected rule/type-inference test suites continue to pass.Fixes phpstan/phpstan#14831