-
Notifications
You must be signed in to change notification settings - Fork 48
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
unset() on already initialised object property? #170
Comments
I'd say if your code isn't special like https://github.com/Ocramius/ProxyManager, it's never valid to unset a property. So it'd be a good fit for phpstan-strict-rules. But there are many things like that in PHP. One could say that using |
From what I have see – with When developer see From my perspective there are valid use-cases when in-class code uses class A {public ?string $x;}
$a = new A();
unset($a->x); // invalid class A {
private string $x;
public function doSth() {
unset($this->x); // valid, as it is internal state
}
}
$a = new A();
$a->doSth(); Here I made a property public. Not sure if this makes sense to allow, as accessing class A {
public string $x;
public function doSth() {
unset($this->x); // (?!)
}
}
$a = new A();
$a->doSth(); For the last example it looks to me that this behaviour should be disabled altogether on class Note: Interesting enough, if you use
|
Let's open discussion, if this code, which breaks type hint of property should be allowed:
https://phpstan.org/r/f5b0a55c-b46e-45d3-9c38-e7c03f164dbf
Problem
I would consider property
$x
to be initialized, there I would not expect it to become uninitialised again. I think it should NOT be allowed to unset value from object outer scope.Any arguments for or against?
The text was updated successfully, but these errors were encountered: