Re: [RFC] str_icontains
| From: | Larry Garfield | Date: | Tue, 24 Jun 2025 13:13:16 +0000 |
| Subject: | Re: [RFC] str_icontains | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127744@lists.php.net to get a copy of this message | ||
On Tue, Jun 24, 2025, at 3:18 AM, Adam Cable wrote:
> On Tue, Jun 24, 2025 at 12:20 AM Larry Garfield <larry@garfieldtech.com> wrote:
>> On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote:
>> > Hello internals,
>> >
>> > I'd like to present my first RFC - str_icontains, a case-insensitive
>> > friend of str_contains
>> >
>> > RFC: https://wiki.php.net/rfc/str_icontains
>> > PR (including tests):
>> > https://github.com/php/php-src/pull/18705
>> >
>> > Previous discussion: https://externals.io/message/127504[$PiªÉÀr°qNz±
>> > X
>> >
>> > Thanks,
>> > Adam
>>
>> When str_contains() was added, a case-insensitive version was deliberately omitted in favor
>> of "just use strtolower() yourself." Have you gone back to see the arguments for that to
>> determine if they're still relevant?
>>
>> (I don't recall the details; I think one of them was function count explosion, but I
>> think there were more.)
>>
>> --Larry Garfield
>
> Thanks Larry.
>
> Yes, I did spend time reading through the past discussions on both
> str_contains and the str_starts/end_with functions.
> I think initial RFCs failed because (a) people felt that the functions
> didn't necessarily bring a whole heap of functionality above userland
> code and (b) the debate about whether case-insensitive versions should
> be included.
>
> Now that these functions exist, it seems weird as a PHP user that
> case-insensitive versions aren't available to easily switch between.
> Obviously we have the UTF-8 question that I've detailed, but I'm hoping
> adding this will solve a tiny issue where people expect this function
> to exist, but it doesn't.
>
> Adam
A discussion of that, and why you think the new position outweighs the original decision, should be
included in the RFC.
(At the moment I'm undecided; yeah it's an easy enough utility to add, but the UTF-8 issue
is real, and one could easily argue that it's stripos() that's wrong, because it's
misleading as it only works on ASCII.)
The ideal answer would be Derick's built-in String object RFC, which I don't think has
been touched in a while, sadly...
--Larry Garfield