Skip to content

PackFormatArgumentMismatch ​

warning native on by default

Group: Probable bugs

Match pack values to the format.

Example ​

php
<?php
$bytes = pack('N2', 11);

Reported:

  • line 2: Match pack values to the format.

Detection ​

  • Parse a constant pack format and report missing required value arguments. Numeric directives consume their repeat counts, string directives consume one value, and padding/position directives consume none. Supported numeric directives are c, C, s, S, n, v, i, I, l, L, N, V, q, Q, J, P, f, g, G, d, e and E. String directives are a, A, Z, h and H; cursor directives are x, X and @. Star counts consume remaining arguments; unknown/unpacked arguments invalidate count proof. Do not report extra arguments here. Exclude q, Q, J and P before PHP 5.6 and g, G, e and E before PHP 7.0; exclude Z before PHP 5.5. Unknown format directives invalidate proof.
  • 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 PackFormatArgumentMismatch and @noinspection PackFormatArgumentMismatch 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": {
    "PackFormatArgumentMismatch": {
      "enabled": false
    }
  }
}

Suppress ​

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

php
// @custos-ignore PackFormatArgumentMismatch

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