ArrayMapMissingCallbackReturn
warning native on by default quick-fixGroup: Probable bugs
Detect array_map with a locally defined callback whose reachable normal exits all return no value and whose body evaluates a discarded expression with a non-void result.
Example
<?php
array_map(function($v){trim($v);}, $names);<?php
array_map(function($v){return trim($v);}, $names);Reported:
- line 2: Return the mapped value from this callback.
Detection
- Report array_map with a locally defined callback whose reachable normal exits all return no value and whose body evaluates a discarded expression with a non-void result.
- 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.
Exceptions (no report)
Ignore writes or transformations after unconditional termination or inside a literal false if branch; these statements cannot establish a missing update or mapped value.
An explicit void return declaration establishes that the callback intentionally supplies no mapped value.
Explicit return null, any value-returning path, unknown callbacks, and purely side-effect callbacks are excluded.
A
str_replace()statement whose arguments can reach the by-reference replacement counter (a fourth positional argument, a namedcountargument, or argument unpacking that hides the binding) is a side effect, not a discarded mapped value. It neither triggers a report nor receives areturn.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.
Fix
An automatic return insertion requires no declared return type; the replacement must not violate a callback return contract. In particular, PHP prohibits returning an expression from void functions.
Add return before the sole discarded expression only for a one-expression callback with no other statements; retain expression text and comments.
A fix is offered only when the concrete prerequisites above are proven. Edits use exact source byte ranges, preserve comments and argument evaluation order, and introduce syntax supported by the configured PHP version. Never invent error-handling policy.
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:
{
"rules": {
"ArrayMapMissingCallbackReturn": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
// @custos-ignore ArrayMapMissingCallbackReturn