Skip to content

ArrayWalkCallbackReturnIgnored ​

warning native on by default

Group: Probable bugs

array_walk ignores callback return values. Use array_map to build transformed values, or update elements through a reference parameter.

Example ​

php
<?php
array_walk($names,fn(string $name)=>strtoupper($name));

Reported:

  • line 2: Use array_map to retain the callback results.

Detection ​

  • Resolved array_walk receives a literal arrow function or closure whose only effect is a returned non-null expression and whose first parameter is by value. Return expression must be side-effect-free, allowing resolved pure string transforms. Highlight callback.
  • A supported pure string builtin in the callback requires its argument to have definitely string type. An untyped argument can invoke intentional object-to-string conversion side effects and does not establish a pure discarded transform. Typed string parameters and directly known string expressions can establish the supported argument contract.
  • Resolve builtin functions, classes, constants and methods; user-defined lookalikes are excluded. Follow only bounded local proof in one lexical scope.
  • Emit one finding per violating operation, not per supporting evidence statement. When the proof is inconclusive, nothing is reported.

Exceptions (no report) ​

  • Void callbacks, by-reference mutation, and callbacks with side effects are excluded.
  • Both standard suppression forms suppress this native ID.

Fix ​

None. Choosing a repair requires intent or additional runtime information.

PHP versions ​

Available throughout supported PHP 5.3–8.5 where the referenced builtin/extension is available. Respect syntax/version-specific receiver contracts; unavailable APIs are not this rule’s concern.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore ArrayWalkCallbackReturnIgnored

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