NeverFunctionFallsThrough
error native on by default PHP ≥ 8.1Group: Probable bugs
Terminate every path in the never function.
Example
Finding:
php
<?php
function halt(bool $stop): never { if ($stop) { exit; } }Reported:
- line 2: Terminate every path in the never function.
Detection
- For a function, method or closure with resolved builtin never return type, report its return type when a reachable path reaches the closing brace. Use bounded control-flow proof, recognizing throw, exit/die, unconditional infinite loops and calls with a resolved never return type. An explicit return is already illegal and is not this fall-through finding.
- Emit one finding per violating operation. Flow facts require a reachable path with no intervening mutation, escaped alias, unknown call involving the tracked value or analysis-budget exhaustion. Uncertain facts cannot prove a violation.
Exceptions (no report)
- Exclude unreachable closing braces, unknown control-flow summaries and budget exhaustion. A conditional throw proves termination only on its throwing branch.
- Exclude shadowed builtin symbols, unresolved required types, incomplete syntax and unsupported PHP versions.
- A
while,do-whileorforloop is not proven to end when its condition (the last one of afor) is a known truthy value such as1, or is built only from literals, constants and operators, such as!falseor1 === 1, whose value the rule does not evaluate. The function is then not reported. A loop whose condition is known falsy, or reads a variable or the result of a call, can still end and does not prevent the report.
Fix
No automatic fix. Choosing a repair requires runtime information, error-handling policy or a semantic decision.
All edits use exact byte ranges, preserve comments and evaluation order, and require syntax supported by the target PHP version. A fix must never add an evaluation or silently change unrelated arguments.
PHP versions
Minimum PHP 8.1.
Configure
In custos.json:
json
{
"rules": {
"NeverFunctionFallsThrough": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
php
// @custos-ignore NeverFunctionFallsThrough