Re: [RFC] Scan results for array_str_contains

From: Date: Thu, 03 Sep 2026 17:19:53 +0000
Subject: Re: [RFC] Scan results for array_str_contains
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-132416@lists.php.net to get a copy of this message
در تاریخ پنجشنبه ۳ سپتامبر ۲۰۲۶، ۲۰:۳۴ Rowan Tommins [IMSoP] < imsop.php@rwec.co.uk> نوشت: > Hi Sepehr, > > On 3 September 2026 17:18:14 BST, "سپهر محمودی" > <sepehrphpr@gmail.com> > wrote: > >- array_filter with str_contains: 8 > >- array_filter with strpos: 8 > >- array_filter with stripos: 6 > >- foreach with str_contains: 6 > >- array_filter with preg_match: 4 > > > >All these different (and sometimes verbose) approaches can simply be > >replaced with a single, clean, and fast native call: > >array_str_contains($haystack, $needle) > > I just went through the results, and found at least 15 of these which are > doing extra logic that couldn't be replaced with the proposed function. > There are probably more I missed, or where the extra logic isn't obvious > because of the way the code is truncated in the report. > > So we're looking at maybe 15 uses in 200 packages. That's still something, > but it's not strong evidence that this is an extremely common task. > > Regards, > > Rowan Tommins > [IMSoP] > ------- Hi Rowan, Thanks for actually going through the results, that's exactly the kind of review I was hoping for. You're right, the scanner only detects the pattern combination, not the full body of the closure. So those numbers represent an upper bound, and some matches do include extra logic. I'll update the RFC to be explicit about this instead of implying all 32 are direct replacements. I'll also try to refine the scan to flag matches that look like a pure substring check, and report both numbers (strict vs. loose matches) so we can see the real lower bound too. Thanks again, Sepehr

« previous php.internals (#132416) next »