Den 2019-07-07 kl. 22:45, skrev Theodore Brown:

On Thu, July 4, 2019 at 9:13 PM Will <w...@wkhudgins.info> wrote:

Hello 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 basic `str_starts_with` and `str_ends_with`
functions very valuable. Currently I either have to implement functions
like this myself in almost every script, or else write repetitious
code like the following:

```php
$needle = "foobar";

if (substr($haystack, 0, strlen($needle)) === $needle) {
     // starts with "foobar"
}
```

To avoid repetition, many developers use the following pattern instead:

```php
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:

```php
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,

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 L

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to