Skip to content

CallbackRequiredArgumentMismatch ​

error native on by default

Group: Probable bugs

Detect array_map with N supplied input arrays and a resolved callback requiring more than N positional parameters.

Example ​

php
<?php
array_map(fn($value, $key) => $key . $value, $items);

function join_pair($left, $right) { return $left . $right; }
array_map('join_pair', $items);

// Not reported: which declaration runs depends on the branch taken.
if (PHP_VERSION_ID < 80000) {
    function label($item, $prefix) { return $prefix . $item; }
} else {
    function label($item) { return (string) $item; }
}
array_map('label', $items);

Reported:

  • line 2: Match the callback parameters to the supplied arrays.
  • line 5: Match the callback parameters to the supplied arrays.

Detection ​

  • Report array_map with N supplied input arrays and a resolved callback requiring more than N positional parameters.
  • Resolve builtin calls and named arguments before checking the contract. Project-local callees are considered only when their bodies or immutable summaries establish the required facts. The default is enabled, with positive proof required.
  • For flow-dependent conditions, require a reachable source-to-use path with no intervening invalidation. Unknown calls, ambiguous aliases or recursion cannot establish definite facts. When the proof is inconclusive, nothing is reported.
  • A string callback naming a project function is resolved only when that fully qualified function name has exactly one declaration in the index, and its body is a direct statement of the analyzed file or of a namespace. Such a declaration is the signature every call reaches.

Exceptions (no report) ​

  • Optional parameters, variadics, unresolved callbacks, and array_map with null callback are excluded.
  • Unresolved targets, incomplete required facts, suppressed findings and PHP versions lacking the referenced API or language feature produce no report. User declarations shadowing builtin names are not builtin contracts.
  • A string callback whose function is declared inside a condition, loop, function body or any other nested statement, or its fully qualified name has multiple indexed declarations (for example one signature per if/else branch, or a function_exists guarded fallback), is unresolved: the signature bound at run time is not known, so nothing is reported.

Fix ​

No automatic fix: an additional input array cannot be invented.

PHP versions ​

Apply only on PHP versions supporting the referenced APIs and syntax (within PHP 5.3–8.5). Builtin behavior and argument contracts follow the configured PHP version. Extension-specific calls require resolved extension API symbols; do not treat same-named application functions as extension calls.

Options ​

None. Enable or disable this rule through normal rule configuration.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore CallbackRequiredArgumentMismatch

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