Re: [RFC] [Discussion] array_match
| From: | Ayesh Karunaratne | Date: | Sun, 23 Aug 2026 15:45:15 +0000 |
| Subject: | Re: [RFC] [Discussion] array_match | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132312@lists.php.net to get a copy of this message | ||
> Do you think the performance gain for such a common use-case justifies having a dedicated
> function, or do you feel the language should strictly prefer the
>
array_filter approach despite the overhead?
>
I don't mean to dismiss Tim's response, especially since you asked him
and his response comes from a lot more experience: I don't think
performance alone is a good reason to introduce a new narrower
function.
I have worked on Drupal, WordPress, Silex, and bespoke code bases,
spending enough time profiling them. An array string search has never
been a bottleneck.
The PHP project itself also has benchmarks of common PHP applications.
If a meaningful number of these common use cases can receive a
performance improvement, then I think we can consider a dedicated
function.
PHP 8.5, for example, has Engine optimizations when comparing a value
against an empty array ( === [] and !== []). These are really
meaningful improvements that do not necessarily change the API
surface.
Newer functions like str_contains, str_ends_with, array_find,
etc had a strong argument in favor of them, that they improve the
ergonomics of the language. With the PFA syntax like Tim mentioned
(and contributed!), I would pick the PFA approach any day of the week:
```php
array_filter($values, str_contains(?, 'foo'));
```
I'm truly thankful that you're spending time to improve PHP, and I
really don't mean to sound discouraging from this email. I just think
that that is still a room in PHP for Engine optimizations and bottle
necks that PHP could use your expertise. A new array_str_contains
function might not get the same approval and agreement and, that,
might in fact, discourage you.
Thank you,
Ayesh.