ForkFailureTreatedAsParent
warning native on by default PHP ≥ 5.3Group: Probable bugs
Handle fork failure separately.
Example
php
<?php
$pid=pcntl_fork(); if ($pid) { echo "parent"; } else { echo "child"; }Reported:
- line 2: Handle fork failure separately.
Detection
- Report direct/unchanged-local pcntl_fork result tested by an if truthiness or negation condition; -1 is truthy. Numeric three-way dispatch remains outside this check.
- No report when failure is already excluded on every path to the test: the comparisons of the fork result with known integers that guard the test leave -1 out. The fork result is the local while it still resolves to the reported call, or the plain assignment that stores that call (
($pid = pcntl_fork()) === -1); a known integer is a literal, possibly signed, or a local whose only value is one ($failed = -1). A comparison guards the test as the condition of an enclosingif/elseifbody, as an earlier condition of the chain for a later arm, as a ternary condition or short-circuit operand, or as the condition of an earlierifwhose body always leaves (return, throw, exit, break, continue), in the same statement list or one enclosing it inside the same function. Soif ($pid === -1) { exit(1); },if ($pid < 0) { return; },-1 === $pidand0 > $pidbefore the test exclude failure, as does testing insideif ($pid !== -1) { … }orif ($pid >= 0) { … }. Unrelated statements between guard and test do not matter. - Resolve builtin functions, extension classes, method receivers, constants and named arguments. Follow unchanged locals and aliases only within the same bounded lexical scope. Require a reachable path; merge branch facts only when all incoming paths establish them.
- Emit one finding at the violating operation, not one per evidence statement. Rebinding, writes, by-reference escape, unresolved calls that can mutate relevant state, and exhausted analysis budgets remove proof.
Exceptions (no report)
- Exclude shadowed builtins, unresolved receivers, incomplete syntax and unknown prerequisite facts. An extension function name alone does not prove an application function is that builtin.
- A dominating valid guard or repair described in Detection prevents the finding. A guard that does not leave, one comparing another call or an earlier value of the local, one placed after the test or inside a closure, and comparisons that -1 does not satisfy (
> -1,< -1,=== 0,!== -1, unknown bounds) do not. Both legacy noinspection and custos-ignore forms suppress this ID.
Fix
No automatic fix. The required repair depends on error handling, data selection, lifecycle ordering or application policy.
All edits use exact byte ranges and preserve comments and evaluation order. Offer no fix when its stated prerequisites cannot be proven or the replacement is unsupported by the configured PHP version.
PHP versions
Requires PHP 5.3 or later and the referenced extension API. Respect method-specific introduction versions within PHP 5.3–8.5; unsupported optional APIs cannot establish facts. Named arguments require PHP 8.0 or later.
Configure
In custos.json:
json
{
"rules": {
"ForkFailureTreatedAsParent": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
php
// @custos-ignore ForkFailureTreatedAsParent