Skip to content

ForkChildFallsIntoParentWork ​

warning native off by default PHP ≥ 5.3

Group: Probable bugs

Terminate or separate the fork child branch. This opt-in rule applies the policy described in Detection.

Example ​

php
<?php
$pid=pcntl_fork(); if ($pid===0) { echo "child"; } echo "continuation";

Reported:

  • line 2: Terminate or separate the fork child branch.

Detection ​

  • Enabled policy reserves the continuation after a strict result === 0 branch for the parent. Report that condition when its nonempty block can fall through and another statement follows. Exclude else/elseif forms and single-statement (unbraced) branches.
  • The block does not fall through when control provably cannot reach the statement after it: it holds a return, throw or exit, a nested block or declare body that does, an if/else chain or try statement whose every path does (a finally that does is enough), a switch with a default whose cases all do, or an endless loop without break. Trailing empty statements are ignored.
  • A break, continue or goto that leaves the child block is not a termination: the child then runs loop iterations or later code the parent also runs, so the block is still reported. Jumps confined to a loop or switch opened inside the block, or to a nested closure, do not count; a jump with a literal level leaves when the level exceeds the number of loops and switches opened inside the block around it (continue 2 in a switch inside a loop of the block stays inside), and one with any other level expression is assumed to leave.
  • Unknown termination summaries are excluded. When the last effective statement of the block is a function, method or static call, report only when the callee resolves to a declaration that can return. No report when the callee cannot be resolved (undeclared or dynamic function, unresolved receiver or class, dynamic method name), when it resolves to an abstract or interface method, when its declared, documented or body-derived return type is never, or when its declaration lives in the analyzed file and its body ends abruptly on every path without any return statement of its own. Builtins that normally return, including pcntl_exec (which returns on failure), are reported.
  • 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. 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": {
    "ForkChildFallsIntoParentWork": {
      "enabled": true
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore ForkChildFallsIntoParentWork

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.