You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect type after strict comparison between null-safe accessed property and false #9394
PHPStan incorrectly strips null from object|null type after a strict comparison between null-safe accessed property and false, with an early exit.
In case a variable contains null and the null safe operator is used to access a property and strictly compare it to false, you effectively get null === false which is always false, so it is impossible to reach the early return. Therefore, the variable should remain nullable.
Strictly comparing to true and loosely comparing to false work as expected. This issue seems to be specific to === false.
Code snippet that reproduces the problem
class Order
{
publicbool$is_pre_order;
}
/** @var Order|null $order */if ($order?->is_pre_order === false) {
return;
}
\PHPStan\dumpType($order); // Dumped type: Order
Activity
phpstan-bot commentedon Oct 30, 2023
@devfrey After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:
Full report
Regression tests
github-actions commentedon Dec 4, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.