Hi
On 19.04.24 23:17, Tim Düsterhus wrote:
On 4/19/24 22:08, Larry Garfield wrote:
There's another issue, though: Will the callback always be given both
$value and $key?
The current implementation always passes both, which, as I just learned,
is inconsistent with `array_filter` which has the `$mode` parameter to
control what to pass to the callback.
Not that I claim that the `$mode` parameter is a good idea from the
typing perspective for static analysis tools, it probably isn't.
Yes, this method always passes both parameters. This has the advantage
that we do not need a third parameter that specifies which parameters
are to be passed to the function. The `array_filter` method was
developed at a time when there were no closures and it was therefore not
trivially possible to change the parameter order of a function (or to
omit a parameter completely). With closures, this is now possible
without any problems.
Converting the method so that it works like `array_filter` would mean
that we would have to introduce new constants (or inconsistent, too: an
enum) for the function that controls this behaviour. Reusing the
constants which are used in `array_filter` is not possible, because the
constant name contains the function name `array_filter`.
Cheers
Josh