-
Notifications
You must be signed in to change notification settings - Fork 479
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
make assigning property via reference impure #3082
Conversation
1f01c4c
to
c2bb307
Compare
$expr, | ||
'propertyAssignByRef', | ||
'property assignment by reference', | ||
false, |
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.
Should be true
, right? There isn't a case where this might still be pure.
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.
It could be pure:
I set certain = false, because theoretically the referenced variable may already be set, and the reference may never be written. In which case it would be pure. But I can't imagine why the reference would be used in such a way in the first place.
<?php
class Foo
{
public ?int $foo;
public function bar(): void
{
$x = &$this->foo;
}
}
$foo = new Foo;
$foo->foo = 5;
$foo->bar();
var_dump($foo->foo);
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.
Alright, cool :)
Thank you! |
Fixes https://phpstan.org/r/cbe5c7f9-f5bd-4101-8cf6-37b7732946d4
I set
certain = false
, because theoretically the referenced variable may already be set, and the reference may never be written. In which case it would be pure. But I can't imagine why the reference would be used in such a way in the first place.