-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Milestone
Description
Bug report
After using ?-> (nullsafe property) in an if-statement, phpstan changes the type to be not-null.
I can see why it's not null inside the if-block, but under the if-block it can still be null
Code snippet that reproduces the problem
https://phpstan.org/r/c2dc0b31-e6c0-45bb-860f-a28cd5ea1844
class H
{
public int|null $a = null;
public self|null $b = null;
public function h(): void
{
\PHPStan\dumpType($this->b);
if ($this->b?->a < 5) {
echo '<5', PHP_EOL;
}
\PHPStan\dumpType($this->b);
if ($this->b?->a > 0) {
echo '>0', PHP_EOL;
}
\PHPStan\dumpType($this->b);
}
}Expected output
10 | Dumped type: H|null
14 | Dumped type: H|null
18 | Dumped type: H|null
Did PHPStan help you today? Did it make you happy in any way?
Every day
Reactions are currently unavailable