Re: RFC [Discussion]: array_find
| From: | Joshua Rüsweg | Date: | Tue, 23 Apr 2024 19:23:38 +0000 |
| Subject: | Re: RFC [Discussion]: array_find | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123191@lists.php.net to get a copy of this message | ||
Hi
On 19.04.24 23:17, Tim Düsterhus wrote:
On 4/19/24 22:08, Larry Garfield wrote: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. TheThere'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 witharray_filterwhich has the$modeparameter to control what to pass to the callback. Not that I claim that the$modeparameter is a good idea from the typing perspective for static analysis tools, it probably isn't.
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