Skip to content

GmpDivisionPairUsedAsNumber ​

error native on by default

Group: Probable bugs

Select a quotient or remainder before using the GMP result.

Example ​

php
<?php
echo gmp_strval(gmp_div_qr('23', '4'));

Reported:

  • line 2: Select a quotient or remainder before using the GMP result.

Detection ​

  • The array result of gmp_div_qr directly or through an unchanged local variable reaches a numeric-operand slot of gmp_strval, gmp_intval, gmp_add, gmp_sub, gmp_mul, gmp_div_q, gmp_div_r, gmp_div_qr, gmp_mod, gmp_cmp, gmp_abs, gmp_neg, gmp_sqrt or gmp_pow (for gmp_pow only the base, its first argument or num, is an operand slot; the exponent is not inspected) without indexing.
  • Resolve builtin functions, extension classes, constants and method receivers, including aliases and supported named arguments. Inspect reachable operations in one lexical scope with bounded local flow.
  • Emit one finding per violating operation. Never infer policy from names or comments. When the proof is inconclusive, nothing is reported.

Exceptions (no report) ​

  • Exclude shadowed or unresolved symbols, incomplete code, unknown required constants, ambiguous receiver identity and unsupported versions. Reassignment, escaping aliases, and unknown calls invalidate dependent flow facts.
  • Both @custos-ignore GmpDivisionPairUsedAsNumber and @noinspection GmpDivisionPairUsedAsNumber suppress this native rule.

Fix ​

None. A safe repair requires choosing values, error handling, or application behavior.

PHP versions ​

Apply throughout PHP 5.3–8.5 only where the extension API and syntax exist. Do not flag API unavailability through this rule.

Options ​

None. Use normal rule configuration to enable or disable the inspection.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore GmpDivisionPairUsedAsNumber

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