Re: array_reject() as counterpart of array_filter()
| From: | Sara Golemon | Date: | Mon, 31 Aug 2020 16:00:23 +0000 |
| Subject: | Re: array_reject() as counterpart of array_filter() | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111742@lists.php.net to get a copy of this message | ||
On Mon, Aug 31, 2020 at 10:35 AM David Rodrigues <david.proweb@gmail.com>
wrote:
>> It should be possible for the engine (at some layer) to look at that
closure
>> and see that it's just negating some proxied call and elide setting up
the
>> intermediate frame. Microoptimizations SHOULD be the engine's job, not
userspace's.
>>
>
> I really think that it should be a good solution, but how hard should it
be to create a proxy like that?
>
We already have a few examples of proxies of this sort.
Closure::fromCallable() comes to mind in particular. We could detect the
fn($x) => !y($x) pattern and replace it with a callable of y with
negation (and a few other common idioms).
I wouldn't vote against a flag on array_filter(), because doing the quick
and easy thing is very much in PHP's DNA, but I think we can cover a lot
more ground with a more general purpose solution that leaves userspace to
deal with bigger problems.
-Sara