Skip to content

Conversation

@johnbillion
Copy link
Contributor

@johnbillion johnbillion commented Oct 13, 2025

There are two PHPStan rules relating to use of the #[\Override] attribute on methods:

  1. method.missingOverride which detects when a method overrides another but is missing the #[\Override] attribute. This rule is operational only when the checkMissingOverrideMethodAttribute config option is set to true.
  2. method.override which 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 checkMissingOverrideMethodAttribute config 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.4. 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 relevance to these rules.

Currently if the following PHP version range config is in phpstan.neon then the #[\Override] attribute rules don't apply and PHPStan won't check their correctness.

phpVersion: min: 70400 max: 80400

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.

@johnbillion johnbillion marked this pull request as ready for review October 13, 2025 19:13
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants