[6.x] Allow #[\Override] on properties (PHP 8.5)#11891
Open
alies-dev wants to merge 1 commit into
Open
Conversation
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
#[\Override] on properties (PHP 8.5)
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 |
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.
PHP 8.5 allows
#[\Override]on properties (the "marking overridden properties" RFC), but Psalm reported a false-positiveInvalidAttributefor that valid usage. The bundled stubstubs/CoreGenericAttributes.phpstubdeclared the attribute withTARGET_METHODonly, soAttributesAnalyzerrejected it on any property.This adds
Attribute::TARGET_PROPERTYto theOverridetarget 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
phpVersionrather 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], whilegetAttributeClassFlagsreads 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 exampleDeprecated).Tests in
tests/AttributeTest.php: property override is now accepted, method override still works, and#[\Override]on a class constant (viaReflectionClassConstant::getAttributes) still errors, pinning the target set so a later change cannot silently broaden it to constants.Fixes #11890