Re: [RFC] [Discussion] array_match
| From: | سپهر محمودی | Date: | Sat, 22 Aug 2026 20:48:25 +0000 |
| Subject: | Re: [RFC] [Discussion] array_match | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132297@lists.php.net to get a copy of this message | ||
در تاریخ شنبه ۲۲ اوت ۲۰۲۶، ۱۹:۱۰ Ayesh Karunaratne <ayesh@php.watch>
نوشت:
> > You can find all the use cases and examples detailed on the RFC page:
> > https://wiki.php.net/rfc/array_match
> >
> > I look forward to hearing your thoughts and feedback on this proposal!
>
>
> I'm thumbs down on this for a few reasons.
>
> 1. We already have
str_contains function. It is more intuitive
> that
> a false strpos call, and it makes an
> array_filter function clean
> too.
>
> ```php
> array_filter($values, static fn($value) => str_contains($value, 'foo'));
> ```
>
> 2. I think this is a quite narrow use case. Even the RFC text example
> is arguably a poor use case for a str_contains check. When
> checking
> file extensions, it should be a str-ends-with check rather than a
> str-contains check.
>
> 3. Echoing what Yuya mentioned, the case sensitivity is quite
> difficult to reach a consensus on, for the same reasons why
> str_icontains RFC was declined. At this stage, I argue we
> should not
> add case-insensitive switches to any new functions.
>
> 4. Functions like this tend to be incomplete; someone else might argue
> for preserving array keys or filtering by array keys. We already have
> array_filter that can do all of it in any way the caller wants.
>
> 5. Finally, and somewhat opinionatedly, the word "match" resonates
> more with regular expressions. preg_match in PHP itself,
> String.match() in JS,
> re.match() in Python, etc to name a few.
>
> Thank you.
> Ayesh.
>
------‐-‐---
Hi Ayesh,
Thank you so much for your constructive feedback. I really appreciate the
points you raised!
Based on your suggestions and the feedback from the list, I have made
several major updates to the RFC. First, to avoid any confusion with
regular expressions, I have renamed the proposal and the function to
array_str_contains. I also removed the third parameter to keep the behavior
strictly aligned with the exact matching of str_contains(), and explicitly
stated that original array keys are preserved.
Regarding your valid point about using array_filter(), I have added a new
subsection under *“Use Cases”* specifically addressing *“Why a native
function instead of array_filter?”*. It highlights the ergonomics and the
performance benefits of avoiding closure overhead and context switching in
C. I also replaced the file extension example with a more practical URL
filtering scenario, as you suggested.
I would be grateful if you could take a look at the updated “Use Cases”
section. You can find the relocated and updated RFC page here:
https://wiki.php.net/rfc/array_str_contains
Thanks again for your time and for helping me improve this proposal.
Best regards,
Sepehr
>