Re: [VOTE] Voting opens for str_starts_with and ends_with functions
| From: | Björn Larsson | Date: | Mon, 08 Jul 2019 18:09:10 +0000 |
| Subject: | Re: [VOTE] Voting opens for str_starts_with and ends_with functions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106181@lists.php.net to get a copy of this message | ||
Den 2019-07-07 kl. 22:45, skrev Theodore Brown:
On Thu, July 4, 2019 at 9:13 PM Will <will@wkhudgins.info> wrote:Having this _ci postfix is a new way of indicating case insensitivity. I think that it might add to negative votes. Personally I think it's a good idea to mimic existing ways, even if they are a bit awkward. How about using a flag or following "tradition", like stri_starts_with & stri_ends_with or str_istarts_with & str_iends_with? That would follow strstr / stristr and str_replace / str_ireplace. I have no voting rights though. r//Björn LHello all, After 15 days of discussion I have opened up voting on the following RFC (https://wiki.php.net/rfc/add_str_begin_and_end_functions).Thank you for your work on this. I'm surprised that so far the vote is so controversial, with 8 votes in favor and 8 opposed. For those voting against adding these functions, can you clarify why? Do you dislike how they are named, or do you not see the need for the case insensitive versions, or is there an issue with the implementation? Personally I'd find the basicstr_starts_withandstr_ends_withfunctions very valuable. Currently I either have to implement functions like this myself in almost every script, or else write repetitious code like the following:$needle = "foobar"; if (substr($haystack, 0, strlen($needle)) === $needle) { // starts with "foobar" }To avoid repetition, many developers use the following pattern instead:if (strpos($haystack, "foobar") === 0) { // starts with "foobar" }However, with longer strings this becomes far less efficient, since PHP has to search through the entire haystack to find the needle position. If this RFC is accepted, these awkward and inefficient approaches could be replaced with straightforward and fast code like this:if (str_starts_with($haystack, "foobar")) { // ... }Please vote on the RFC if you haven't already. Clarification would be appreciated if don't feel that these functions would be a good addition. Best regards, Theodore Hi,