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
False positive "Coalesce operator ?? is unnecessary" when the last method in the chain has return type null #15134
I've updated from 2.2.5 to the latest (2.2.9/2.2.10) and noticed that phpstan now complains when null is the last type in the ?? chain. It is fine for variables, but not fine if the last item is the method with null type. For example, the parseSpace() method cannot be deleted because it may perform some work.
abstractclass Parser {
protectedfunctionparseExpressionChild(bool$value): ?Node {
return$this->parseNumber($value) // Coalesce operator ?? is unnecessary because the left side is always set and the right side is null.
?? $this->parseSpace($value);
}
abstractprotectedfunctionparseNumber(bool$value): ?A;
protectedfunctionparseSpace(bool$value): null {
if ($value === false) {
thrownewLogicException('Value is not valid.');
}
returnnull;
}
}
Activity
phpstan-bot commentedon Sep 12, 2026
Closed via merging phpstan/phpstan-src#6418
github-actions commentedon Oct 14, 2026
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.