Repository navigation
Check property hooks, asymmetric visibility and all prototypes in overriding rules - #7080
Merged
Merged
Conversation
…ethodRule Extract the checks shared with property hooks into OverridingMethodCheck and let MethodParameterComparisonHelper compare any method reflection, so OverridingPropertyRule can reuse them for hooks. Amp-Thread-ID: https://ampcode.com/threads/T-01a1df04-9cc5-7608-a3ae-ede0c3cf05e5
ondrejmirtes
force-pushed
the
overriding-rules-php-src
branch
from
November 15, 2026 14:59
cc66ced to
3af7847
Compare
…ngPropertyRule - set visibility can't be narrowed - hooks are checked against the overridden hooks: final, by-ref get, set parameter contravariance, abstract, #[\Override] (missing one reported with checkMissingOverrideMethodAttribute) - backed property can't implement a wider abstract set hook - get hook of a property backed by its parent can't return by reference when there's a set hook - the property is checked against every interface declaring it - iterable is the same type as array|Traversable Hooks wrong by themselves are not compared with the overridden hooks. Amp-Thread-ID: https://ampcode.com/threads/T-01a1df04-9cc5-7608-a3ae-ede0c3cf05e5
…ive types Native type of an overriding constant is a fatal error in PHP, so it's no longer behind checkPhpDocMethodSignatures. Amp-Thread-ID: https://ampcode.com/threads/T-01a1df04-9cc5-7608-a3ae-ede0c3cf05e5
ondrejmirtes
force-pushed
the
overriding-rules-php-src
branch
from
November 15, 2026 15:03
3af7847 to
27520ab
Compare
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.
Situations found by running PHPStan over the php-src
PHP-8.5branch tests that expect an inheritance fatal error (260 tests, 21 previously got no error, now 10). Every new error was verified against real PHP 8.4, and the 1147 php-src tests in the same areas that expect no error got no new errors (only theiterablefalse positives below disappeared).OverridingPropertyRule
setvisibility (public protected(set)→public private(set)), including the implicitprotected(set)of readonly propertiesOverridingMethodRule(extracted intoOverridingMethodCheck): final hook,getoverriding&get,setparameter contravariance, abstract hook,#[\Override]on a hook that overrides nothing, and missing#[\Override]on hooks withcheckMissingOverrideMethodAttributeset(int|string $value)hook it implements&gettogether withseton a property backed by its parent propertyiterableis the same type asarray|Traversable(false positive)Hooks that are wrong by themselves (reported by
SetPropertyHookParameterRuleand PHP itself) are not compared with the overridden hooks, so the same mistake isn't reported twice. Hook messages use the existing hook wording, e.g.Get hook for property B::$prop overrides final get hook for property A::$prop.OverridingMethodRule
voidoverridingmixedOverridingConstantRule
finalconstant in the second interface or in the parent next to an interface was missed)checkPhpDocMethodSignatures, it's a fatal error in PHPphpstan/phpstan#12336
Items this covers:
&getrequires&get#[\Override]attribute can be applied to a hookNot covered
Class X inherits both A::C and B::C, which is ambiguousfor constants (needs a class-level rule)MethodPrototypeFinderreturns only oneOverridingPropertyRuleuntil that's fixed in the fork