Skip to content
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

Readonly object ArrayAccess assignment detection #8929

Open
netpok opened this issue Feb 21, 2023 · 0 comments · May be fixed by phpstan/phpstan-src#3795
Open

Readonly object ArrayAccess assignment detection #8929

netpok opened this issue Feb 21, 2023 · 0 comments · May be fixed by phpstan/phpstan-src#3795
Labels
Milestone

Comments

@netpok
Copy link

netpok commented Feb 21, 2023

Bug report

ArrayAccess offsetSet mistakenly detected as assignment of the property itself.

Code snippet that reproduces the problem

https://phpstan.org/r/a97143d1-7447-4a63-8b43-683f17783572

Expected output

Since WeakMap implements ArrayAccess the $this->cache[$key] = $value assignement wont update the object itself but calls a method on it. I think it should not generate the warning.

Did PHPStan help you today? Did it make you happy in any way?

Yes, keep up the good work.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Feb 21, 2023
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 24, 2025
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
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 24, 2025
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
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 24, 2025
of course just checking for ArrayAccess isn't enough - it's only valid
for index assignment operations 🤦
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 28, 2025
of course just checking for ArrayAccess isn't enough - it's only valid
for index assignment operations 🤦
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 28, 2025
of course just checking for ArrayAccess isn't enough - it's only valid
for index assignment operations 🤦
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 28, 2025
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
pilif added a commit to pilif/phpstan-src that referenced this issue Jan 28, 2025
of course just checking for ArrayAccess isn't enough - it's only valid
for index assignment operations 🤦
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants