-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Description
Bug report
When I set a property, then call a function that mutate that property and finally check the property value with a if statment, PHPStan think that my property still have the original value, but only if the function return something.
Code snippet that reproduces the problem
class HelloWorld
{
private bool $foo;
public function theMethod(): int {
$this->foo = true;
//$this->changeFoo(); // <-- NO ERROR with the return void method
$this->changeFooWithReturn(); // <-- ERROR with the return int method
if ($this->foo) { // <-- PHPStan error : "If condition is always true."
return 1;
}
return 0;
}
public function changeFoo(): void
{
$this->foo = false;
}
public function changeFooWithReturn(): int
{
$this->foo = false;
return 0;
}
}https://phpstan.org/r/f711eb37-04be-42c9-bbfd-c79515b0e919
Expected output
PHPStan should not detect any issue here
Reactions are currently unavailable