Skip to content

fix(override): #[\Override] on a property without a parent property is an InvalidOverride - #14390

Merged
orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/14006-override-property
Nov 22, 2026
Merged

orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/14006-override-property

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PHP 8.5: #[\Override] on a property without a matching non-private property in a parent class or interface is a fatal error. Psalm reports no InvalidOverride, as it does for methods.
Before

class Base { public int $a = 1; }
final class Child extends Base {
    #[\Override]
    public int $b = 2; // no issue
}

After

    #[\Override]
    public int $b = 2; // InvalidOverride: Property $b does not match any parent property

A private parent property does not count, a property of an interface or a parent class does (new tests).
Fixes #14006
Fixes #14044

Not reported: #[\Override] on a property of an interface that extends nothing (interfaces do not go through addContextProperties()).

…meo#14006

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace jirkace changed the title feat(override): fix(override): #[\Override] on a property without a parent property is an InvalidOverride Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 751 91.0 25 908 53 462 682
✅ symfony 3 600 202.8 $\color{gray}{\textsf{-4.2\%}}$ 50 611 98 405 1 528
✅ doctrine-orm 381 17.6 $\color{gray}{\textsf{+0.8\%}}$ 3 481 6 143 0
✅ psl 617 22.1 $\color{gray}{\textsf{+0.2\%}}$ 1 375 5 615 1
✅ phpunit 455 14.3 $\color{gray}{\textsf{-2.2\%}}$ 1 731 3 410 18
✅ php-parser 226 9.3 $\color{gray}{\textsf{-0.6\%}}$ 17 132 21 025 0
✅ tempest 895 27.4 $\color{gray}{\textsf{+1.6\%}}$ 5 047 10 528 252
✅ amphp-amp 68 1.8 29 49 0
✅ webmozarts-assert 272 4.6 $\color{gray}{\textsf{-0.6\%}}$ 577 2 720 0
✅ guzzle-promises 44 $\color{gray}{\textsf{+0.1\%}}$ 1.6 $\color{gray}{\textsf{-0.6\%}}$ 155 434 2
✅ monolog 135 5.5 $\color{gray}{\textsf{-0.2\%}}$ 913 2 479 10
✅ drupal 4 841 195.3 $\color{gray}{\textsf{+0.3\%}}$ 97 591 169 293 583
Total 13 286 593.4 $\color{gray}{\textsf{-1.3\%}}$ 204 550 373 563 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head ee5578b · base 7bfe967 (merge-base) · workflow run

@jirkace

jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • From PHP 8.5, #[\Override] on a property that overrides no non-private property of a parent class or interface reports InvalidOverride (as it does for methods). Verified by the new OverrideTest cases: a property of a parent class or an interface is accepted, a private parent property is reported.
  • Not changed: methods, constants; below PHP 8.5 nothing is reported. Not run: the full suite (CI).

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The check is in the right place and I found no false positive (parent class, interface, interface of a
parent, static, abstract hooked property, property a parent got from a trait). Two cases that PHP 8.5 rejects
are still missed, though:

  1. A property that comes from a trait. PHP checks the attribute in the class that uses the trait, and Psalm
    already does so for trait methods:

    trait T {
        #[\Override]
        public int $x = 1; // PHP 8.5: Fatal error, no matching parent property; Psalm: no issue
    }
    final class A { use T; }

    $property_class_name === $fq_class_name excludes it, since the declaring class is the trait. Comparing the
    class of $appearing_property_id instead should cover it (it is the using class for a trait property and the
    parent for an inherited one).

  2. A promoted property:

    final class C {
        public function __construct(#[\Override] public int $x) {} // PHP 8.5: Fatal error; Psalm: no issue
    }

    The scanner keeps the parameter's attributes only on the parameter storage, not on the promoted property's.

Could you handle both, with test cases for each (invalid: trait without parent, trait whose parent property is
private, promoted without parent; valid: trait and promoted property with a public parent property)?

Smaller points:

  • An #[\Override] property of an interface that extends nothing is also a fatal error and isn't reported
    (interfaces don't go through addContextProperties()); fine to leave out, but please say so in the
    description, as it says the PR fixes the issues.
  • $property_storage->suppressed_issues ?: $storage->suppressed_issues: a property suppressing some other
    issue makes a class-level @psalm-suppress InvalidOverride ignored; merging both lists avoids that.
  • For an anonymous class, the message shows the internal class name; the method message only shows the member name.

jirkace and others added 2 commits November 21, 2026 16:57
…perty is checked too

A property of a trait is checked in the class that uses it (the class of its appearing property id), the
attributes of a promoted parameter are kept on the promoted property, the suppressions of the property
and of the class are merged and the message names the property only, like the method message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Pushed ee5578b.

  1. A trait property is checked in the class that uses it: the condition compares the class of $appearing_property_id (overrideOfAPropertyOfATraitWithoutAParentProperty, ...WhoseParentPropertyIsPrivate; valid with a public parent property in overrideOfAPropertyFromATraitAndOfAPromotedPropertyWithAParentProperty).
  2. The attributes of a promoted parameter are kept on the promoted property (overrideOfAPromotedPropertyWithoutAParentProperty, and the valid counterpart in the same valid case).
  3. Interface-only #[\\Override] properties stay unreported, said in the description. The suppressed issues of the property and of the class are merged, and the message is Property $x does not match any parent property like the method one (no internal anonymous class name). The old test messages are updated. All three new invalid cases fail on the previous head. @orklah

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jirkace!

@orklah
orklah merged commit 0b494af into vimeo:master Nov 22, 2026
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[8.5] #[\Override] on a property that overrides nothing is not reported [8.5] #[\Override] on a property without a parent property is not reported

2 participants