Re: Array arguments for str functions

From: Date: Mon, 16 Mar 2026 00:41:30 +0000
Subject: Re: Array arguments for str functions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-130361@lists.php.net to get a copy of this message
On 2026-03-15 20:20, Barel 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 functions were added after it was pointed out that userland implementations tended to result in the information being derived internally and then thrown away, requiring the user to reconstruct it; it made sense to yield that internal information directly. For this extension, I'm not sure what the advantages are over simple function composition (array_any was introduced for exactly this sort of job and is applicable to any function). Or disadvantages (e.g. more complex function signature).

« previous php.internals (#130361) next »