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
switch (true) whose cases cover every value reports return.missing, unlike the equivalent if/elseif #15892
A switch (true) whose cases cover every possibility, with a return in each case, still reports a missing return. PHPStan itself knows the last case is always true. The equivalent if/elseif chain has no return.missing error.
Actual output (line numbers refer to the playground snippet):
5: Function signSwitch() should return string but return statement is missing.
8: Comparison operation ">=" between int<0, max> and 0 is always true.
17: Comparison operation ">=" between int<0, max> and 0 is always true.
No return.missing on line 5, the same as for signIf(). After a case whose condition true === <expr> is always true and which always terminates, the code after the switch is unreachable. This is exactly how an if/elseif chain with an always-true last condition is already handled. Whether the always-true comparisons themselves are reported is a separate question and is fine either way.
Activity
ondrejmirtes commentedon Nov 30, 2026
This needs to: