Skip to content

IntdivZeroDivisor ​

error native on by default PHP ≥ 7.0

Group: Probable bugs

Identify intdiv with second operand proven integer zero.

Detection ​

  • Report intdiv with second operand proven integer zero.
  • Resolve builtin functions, classes, constants and methods, including imports and supported named arguments. Follow only bounded local facts within one lexical scope. Receiver and argument provenance must establish the specific API contract; variable names and comments never prove intent.
  • A variable divisor counts as zero only when the single assignment reaching the call is an integer zero and nothing else can have rewritten the variable before the call runs. Besides plain, compound and reference assignment, these writes cancel the proof when they sit earlier in the same function body (or the same file for top-level code), or anywhere in that scope when the call is inside a loop: ++ or -- on the variable, a closure capturing it by reference, a foreach whose key or value target names it (destructuring included), a catch binding of that name, and a call to extract(). Code inside a nested function does not count, apart from that by-reference capture.
  • Report one finding per violating operation. A reachable path, unchanged value identity and applicable API behavior are required. Intervening mutation, unknown calls involving tracked values, escaped aliases or exhausted analysis budgets invalidate proof.

Exceptions (no report) ​

  • Exclude unresolved required symbols, user-defined lookalikes, incomplete syntax, unknown required values and unsupported versions.
  • A counter that starts at zero and is stepped before the division is not reported, whether the step is in straight-line code, in an enclosing loop or in a loop that completed earlier. A step located after the call, outside any loop around it, does not cancel the report.
  • Both @custos-ignore IntdivZeroDivisor and @noinspection IntdivZeroDivisor suppress this native rule.

Fix ​

None. A repair requires a semantic decision or application error-handling policy.

PHP versions ​

Requires PHP 7.0 or later. Do not apply extension contracts when the resolved API is unavailable. Gate syntax and version-specific behavior to the configured target.

Configure ​

In custos.json:

json
{
  "rules": {
    "IntdivZeroDivisor": {
      "enabled": false
    }
  }
}

Suppress ​

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

php
// @custos-ignore IntdivZeroDivisor

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