-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow write access to offsets of readonly ArrayAccess properties #3795
base: 2.1.x
Are you sure you want to change the base?
Conversation
one sec - will fix to make this work properly with old PHP versions |
This pull request has been marked as ready for review. |
ok. much better. I don't think the failing rector integration test is related to this at all |
@@ -89,6 +91,10 @@ public function processNode(Node $node, Scope $scope): array | |||
continue; | |||
} | |||
|
|||
if ((new ObjectType(ArrayAccess::class))->isSuperTypeOf($propertyReflection->getNativeType())->yes()) { | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a wrong fix. You can't say that in general.
If I have private readonly ArrayAcess $a
and I do $this->a = new Foo()
twice, PHP does not allow that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 of course - you're right.
I have pushed a patch to expand the test to test for your case and to also check that we're dealing with a SetOffsetValueTypeExpr
90de7f8
to
8b59053
Compare
In case a readonly property is an object which implements ArrayAccess, offet accesses to said property are turned into method calls on PHP's side and are allowed even on read-only properties. this fixes phpstan/phpstan#8929
of course just checking for ArrayAccess isn't enough - it's only valid for index assignment operations 🤦
In case a readonly property is an object which implements ArrayAccess, offet accesses to said property are turned into method calls on PHP's side and are allowed even on read-only properties.
this fixes phpstan/phpstan#8929