On Fri, Aug 12, 2016 at 8:37 PM, <w...@wkhudgins.info> wrote:

> I've updated the RFC to reflect the discussion here and on github. You may
> see it at
> https://wiki.php.net/rfc/add_str_begin_and_end_functions . You can see
> the github PR at https://github.com/php/php-src/pull/2049 .
>
> The motivation for these changes was to maximize consistency between the
> proposed functions and existing PHP string functions. The goal is to make
> these functions feel natural and add functionality to the language without
> cluttering it up.
>

Generally, +1. A few thoughts.

First, the RFC refers to these working on "characters". I assume you mean
ASCII characters and these actually work strictly on bytes. Working on
"characters" would be more in-line for a multi-byte extension. Would you
please clarify this point?

Second, and related to the multi-byte issue: do the case insensitive
versions honor case-folding in a multi-byte fashion? Either way, it's
probably a good idea to separate the vote between the sensitive and
insensitive versions because this is fundamentally a different, and perhaps
more contentious, question.

Third, perhaps these functions could provide more information than just
yes/no. Return boolean TRUE if and only if the needle completely
begins/ends the haystack, otherwise return INT representing the length in
common. Yes, that'll probably be a trap for new developers who don't honor
===, but that could be illuminated in docs. Formally:

boolean|int str_begin(string $needle, string $haystack)
boolean|int str_end(string $needle, string $haystack)

For example:

str_begin('http://', 'http://example.com') === true
str_begin('http://', 'https://example.com') === 4

Finally, since the RFC will fuel the final documentation, it might be a
good idea to use needle/haystack terminology in the function signatures for
some kind of consistency.

Reply via email to