Remove PHP version constraint from the #[\Override] attribute rules#4436
Merged
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom Jan 24, 2026
Merged
Conversation
Collaborator
|
This pull request has been marked as ready for review. |
2218870 to
6060101
Compare
Member
|
Makes total sense! I also did the same thing for properties. Sorry for taking so long. Thank you! |
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.
There are two PHPStan rules relating to use of the
#[\Override]attribute on methods:method.missingOverridewhich detects when a method overrides another but is missing the#[\Override]attribute. This rule is operational only when thecheckMissingOverrideMethodAttributeconfig option is set to true.method.overridewhich detects when#[\Override]is used on a method which does not override a method.Currently these rules are triggered when PHP 8.3 or higher is in use, because that's the version that introduced support for this attribute.
However both of these rules are opt-in and therefore don't need to be constrained by PHP version. The former is explicitly opt-in via the
checkMissingOverrideMethodAttributeconfig option and the latter is implicitly opt-in via the existence of an#[\Override]attribute on a method.This PR proposes removing the PHP version constraint from these rules so they can be applied to a codebase which supports versions of PHP older than 8.3 and still benefit from static analysis by PHPStan.
What's the use case?
I work on codebases which support PHP 7.4 to 8.5. I want to make use of the
#[\Override]attribute on methods and have PHPStan confirm that their usage is correct. The fact that the codebase is compatible with PHP < 8.3 should be of no concern to these rules.Currently if the following PHP version range config is in
phpstan.neonthen the#[\Override]attribute rules don't apply and PHPStan won't check their correctness.Is this a breaking change?
I don't believe this should be considered a breaking change, however there may be codebases that are using
#[\Override]attributes and a supported version of PHP lower than 8.3 that don't realise these rules are not currently being applied. These rule changes may cause previously passing incorrect use of#[\Override]to now fail, which arguably is a bugfix.