Skip to content

[6.x] Allow #[\Override] on properties (PHP 8.5)#11891

Open
alies-dev wants to merge 1 commit into
vimeo:6.xfrom
alies-dev:fix/11890-override-property-target
Open

[6.x] Allow #[\Override] on properties (PHP 8.5)#11891
alies-dev wants to merge 1 commit into
vimeo:6.xfrom
alies-dev:fix/11890-override-property-target

Conversation

@alies-dev

@alies-dev alies-dev commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

PHP 8.5 allows #[\Override] on properties (the "marking overridden properties" RFC), but Psalm reported a false-positive InvalidAttribute for that valid usage. The bundled stub stubs/CoreGenericAttributes.phpstub declared the attribute with TARGET_METHOD only, so AttributesAnalyzer rejected it on any property.

This adds Attribute::TARGET_PROPERTY to the Override target set. Class constants stay excluded, matching the engine, which fatals on #[\Override] on a class constant (allowed targets: method, property).

The stub loads unconditionally, so the property target now applies to every configured phpVersion rather than 8.5+ only.

Why not guarding it to 8.5+: per-version attribute target sets cannot be expressed through stubs: version stubs are cumulative (there is no "load only below 8.5" hook), and a class cannot be redeclared with different flags (the override path reuses the existing storage and appends a second #[Attribute], while getAttributeClassFlags reads only the first). The remaining trade-off, not flagging #[\Override] on a property when targeting PHP below 8.5, is consistent with how Psalm already treats attribute availability in general (for example Deprecated).

Tests in tests/AttributeTest.php: property override is now accepted, method override still works, and #[\Override] on a class constant (via ReflectionClassConstant::getAttributes) still errors, pinning the target set so a later change cannot silently broaden it to constants.

Fixes #11890

PHP 8.5 permits #[\Override] on properties (RFC: marking overridden
properties), but the bundled stub declared the attribute with
TARGET_METHOD only, so Psalm reported a false-positive InvalidAttribute
for valid property usage.

Add TARGET_PROPERTY to the Override attribute target set. Class constants
stay excluded, matching the engine, which rejects #[\Override] on a class
constant.

The stub loads unconditionally, so the property target applies to every
analysis_php_version rather than 8.5+ only. Per-version attribute target
sets cannot be expressed through stubs (version stubs are cumulative and a
class cannot be redeclared with different flags), and this matches how
Psalm already handles other attributes such as Deprecated.

Fixes vimeo#11890
@alies-dev alies-dev changed the title fix: allow #[\Override] on properties (PHP 8.5) [6.x] Allow #[\Override] on properties (PHP 8.5) Jun 23, 2026
@alies-dev

alies-dev commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

UPD: I'll create another PR, stacked on that, that will have a proper reporting and auto-fix features. The currect one is a hotfix no-brainer one aims to quick-patch that noisy issue

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.

False positive InvalidAttribute: #[\Override] on properties is valid in PHP 8.5

1 participant