d7DetectabilityOperational debt — how invisible misuse is to your safety net
Closest to 'only careful code review or runtime testing' (d7). The key misuse — forgetting array_values() after array_filter() — produces no error or warning at runtime in most paths; it silently preserves non-sequential keys and only manifests as a bug when JSON encoding converts the array to an object instead of an array, or when downstream code assumes 0-indexed keys. The detection_hints list only Rector, which handles refactoring patterns rather than detecting this specific key-preservation gotcha automatically.
e3EffortRemediation debt — work required to fix once spotted
Closest to 'simple parameterised fix' (e3). The quick_fix notes adding array_values(array_filter($arr)) when sequential keys are needed — a small, localised change. It may need to be applied across multiple call sites if the pattern is repeated, but each fix is a simple wrapper addition rather than a structural refactor.
b3BurdenStructural debt — long-term weight of choosing wrong
Closest to 'localised tax' (b3). The choice to use array_map/filter/reduce is localised to the specific transformation logic. It applies broadly across web/cli/queue contexts (per applies_to), but each usage is independent; there is no strong gravitational pull on the rest of the codebase. Nested usage or large-dataset concerns are contained to the affected code paths.
t5TrapCognitive debt — how counter-intuitive correct behaviour is
Closest to 'notable trap' (t5). The misconception is clearly documented: array_filter() preserves original keys, not re-indexing to 0-based. This contradicts many developers' intuition that filtering produces a clean sequential array, and it causes subtle JSON encoding bugs (object vs. array). It is a widely-known gotcha that most PHP developers encounter, placing it squarely at t5.
About DEBT scoring →
scored by claude-sonnet-4-6 · 2026-05-11 · reviewed by human
TL;DR
PHP's array_map(), array_filter(), and array_reduce() enable functional-style data transformation pipelines — cleaner than imperative loops for many common patterns.
Explanation
Functional array operations: array_map(fn, array) — transforms each element, returns new array. array_filter(array, fn) — removes elements where fn returns false, preserves keys. array_reduce(array, fn, initial) — folds array to single value. Combining: array_values(array_filter(array_map(fn, $data))). PHP 8.1 arrow functions (fn($x) => $x*2) make these concise. Caveats: array_filter() preserves keys — use array_values() to re-index. array_map() with multiple arrays fills shorter ones with null. For large datasets, generators are more memory-efficient than array_map.
Common Misconception
✗ array_filter() re-indexes the array — it preserves original keys. Use array_values(array_filter($arr)) to get a 0-indexed result.
Why It Matters
FP-style array operations express intent more clearly than imperative loops and are easier to compose, test, and reason about.
🧱FUNDAMENTALS— new to this? Start with the ground floor.
ArraygeneralAn ordered collection of values under one name, accessed by position ([0], [1]) or, in associative form, by named key.
Almost all real data arrives as collections — rows from a database, items in a cart, JSON from an API. Fluency with arrays and their transform functions is the difference between three lines and thirty.
💡 When looping with manual indexes, check the boundary twice — or use foreach and never index by hand at all.
PHPphpA server-side scripting language that generates web pages and APIs — the code runs on the server, and only its output (usually HTML or JSON) reaches the browser.
PHP is often the first server-side language people meet, and understanding its execution model — script starts fresh on every request, no memory between requests — explains most of how the web backend works: sessions, databases, and caching all exist to bridge that per-request amnesia.
💡 Start with PHP 8.x, declare(strict_types=1), and PDO — skip any tutorial that mentions mysql_query().
Replace imperative loops with array_map/filter/reduce for simple transformations. Add array_values() after array_filter() when sequential keys are needed.