- poisonal
- /
- Predicting The Needle In Haystack Arguments
- /
- worked example
worked example
Resolving Callback Predicates
Filter vs Map Argument Order
Filter vs Map Argument Order
You're writing a small data pipeline in PHP and keep mixing up whether the callback or the array comes first when calling `array_filter` and `array_map`. You need a reliable way to remember the correct order for each.
- 1.Write out both function signatures side by side: `array_map($callback, $array, ...arrays)‘and‘arrayfilter(array, $callback, $mode)`.—Seeing them stacked exposes that the order is actually reversed, not just different syntax.
- 2.Check why `array_map` puts the callback first: it can accept multiple arrays to combine element-by-element, so PHP needs to know the transformation rule before it knows how many arrays follow.—Variadic arguments only work cleanly if the fixed argument comes before the open-ended list.
- 3.Check why `array_filter` puts the array first: the callback parameter was added years after the function's original release, and making it optional required it to come after the required array.—Backward compatibility, not logical design, decided this order.
- 4.Build a small test case: filter an array of numbers for even values, then map the same array to double each value, writing both calls from memory.—Producing the code yourself catches whether the rule has actually stuck or just sounds familiar.
- 5.Attach a verbal anchor: 'filter starts with the array being filtered; map starts with the machine doing the mapping.'—A short phrase outlasts a memorized argument list when you're coding under time pressure.
When two similar functions disagree in argument order, the mismatch usually traces back to each function's separate history, not a shared design logic, so it's safer to memorize them individually than to assume a pattern.
Pass it alonga thing worth keeping
Where this came from
This is one of 3 pieces in the chapter Predicting The Needle In Haystack Arguments.
It started 2 steps back, when somebody asked poisonal PHP And Why It Still Runs The Web
show the trail
← before thiscomponentMethod Chaining Target RulecomponentResolving Callback Predicatesyou are here
Open the chapterMade 16 September 2026. Written by poisonal ai.
↓ learn more
Your turn
Name a topic and poisonal makes you a whole spread of pieces like this one.
