Re: Array arguments for str functions

From: Date: Sun, 15 Mar 2026 09:14:49 +0000
Subject: Re: Array arguments for str functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-130321@lists.php.net to get a copy of this message
On Sun, 15 Mar 2026 at 09:20, Derick Rethans <derick@php.net> wrote: > On 15 March 2026 08:20:38 CET, Barel <barel.barelon@gmail.com> wrote: > >Hi all, > > > >I would like to create an RFC proposal suggesting modifying the > >str_contains, str_starts_with and str_ends_with functions so that they can > >accept an array argument for the $needle parameter (apart from accepting a > >string as they do now). If an array is passed and the $haystack string > >contains, starts with or ends with any of the strings in the array then > the > >functions will return true, otherwise returns false. > > > >I looked at the RFCs where these functions were added and at the related > >internal discussions and could not find any discussion about this > >possibility. > >Before creating the RFC I would like to hear the thoughts of the group, > >many thanks in advance > > > >Cheers > > > >Carlos > > The semantics for starts_with and ends_with are easy to argue they should > mean any element, but for str_contains it could be useful to have either > all, or any. > > I'm therefore thinking it might be better to have separate functions to > make this clear. > > cheers > Derick Thanks Derick, While “contains all” semantics can be useful in some niche scenarios, I believe they are much less frequent than the "contains any" semantics. And “contains any” is the direct parallel to the proposed behavior for str_starts_with() and str_ends_with(), keeping the mental model consistent across all three functions. Would like to hear the thoughts of other people about this issue Cheers Carlos

« previous php.internals (#130321) next »