> var_dump(array_filter(['foo', '', 'bar'], 'strlen', true)); > > Warning: strlen() expects exactly 1 parameter, 2 given in - on line 1 > > Not only do we trigger the error handler (a large enough array causes a > performance issue), but we also get back an empty array as a result. That's > BC and performance loss that's simply unacceptable, so defaulting the > behavior to pass the key is simply out of the question.
Existing code won't pass that third, true, argument to array_filter(), and thus will not break. Nevertheless, I'd say go with a new array_filter_key() function, because that permits using existing one-parameter functions like that strlen as a callback, instead of forcing two-parameter callback functions. Another alternative might be to go with a third argument to array_filter(), but make that an integer with ORable constants ARRAY_FILTER_KEY, ARRAY_FILTER_VAL - only one of them set calls with a single argument, both set call with two arguments. best regards Patrick