Skip to content

RequiredPhpVersionVisitor: report promoted properties as requiring PHP 8.0#5882

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-sg4ptoj
Jun 15, 2026
Merged

RequiredPhpVersionVisitor: report promoted properties as requiring PHP 8.0#5882
staabm merged 1 commit into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-sg4ptoj

Conversation

@phpstan-bot

Copy link
Copy Markdown
Collaborator

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 a Node\Param with any modifier flag ($node->flags !== 0) as requiring PHP 8.0 with reason promoted properties. The existing readonly (8.1) and asymmetric-visibility (8.4) checks still win via require() taking the highest version.
  • tests/PHPStan/Build/RequiredPhpVersionCommentTest.php: added testDetectedVersion cases for public/protected/private promoted properties (all 8.0) and a negative case proving a non-promoted parameter requires nothing.
  • Added <?php // lint >= 8.0 comments to the 24 existing fixtures that use promoted properties without a lint comment, preserving total line counts so line-sensitive assertType/error assertions are unaffected.

Root cause

A promoted property is the only case where a Node\Param carries 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

testDetectedVersion now asserts that public/protected/private promoted properties are detected as PHP 8.0 and that a non-promoted parameter is detected as null. These fail without the fix. The full testFixtureHasRequiredLintComment data-provider test passes after the 24 fixtures received their // lint >= 8.0 comment, and the affected rule/type-inference test suites continue to pass.

Fixes phpstan/phpstan#14831

…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 staabm merged commit 289ecd0 into phpstan:2.2.x Jun 15, 2026
389 of 390 checks passed
@staabm staabm deleted the create-pull-request/patch-sg4ptoj branch June 15, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RequiredPhpVersionVisitor should check for promoted properties

2 participants