Repository navigation
Look up by-reference parameters of methods called on typed properties of $this - #7238
Merged
Merged
Conversation
… of $this PreservedPropertiesVisitor treated every argument of a method call on another object as a possible by-reference write, so a narrowed property passed to $this->dependency->method() was forgotten after a call on $this that runs that code. When the receiver is a property of $this, the argument is now recorded like the ones of static calls and functions, and PreservedPropertiesResolver checks the parameter of the method on the property's declared type. Amp-Thread-ID: https://ampcode.com/threads/T-01a22093-364f-7598-b2ca-80a68e13ef9e
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.
PreservedPropertiesVisitortreated every argument of a method call on another object as a possible by-reference write, because the callee's signature is not known while the file is parsed. A narrowed private property passed to$this->finder->find($this->id)was therefore forgotten after a call on$thisthat runs that code.When the receiver is a property of
$this, the argument is now recorded like the arguments of static calls,newand functions, as'Class::$property->method'.PreservedPropertiesResolverlooks up the method on the property's declared type, withnullremoved so?Finderand?->work too. Overrides cannot change whether a parameter is by reference. The property is still treated as written when the type has no class (mixed,object), the method is magic, or the call is in a trait or an anonymous class.Neither class is shadowed by turbo-ext. The full test suite and
make phpstanpass.Closes phpstan/phpstan#15868
Amp thread: https://ampcode.com/threads/T-01a22093-364f-7598-b2ca-80a68e13ef9e