On 2016-08-13 04:34, Simon Welsh wrote:
On 2/08/2016, at 8:52 AM, w...@wkhudgins.info wrote:

Hello,

I recently emailed the group about submitting an RFC for str_begins() and str_ends() functions. The RFC has now been officially submitted and is viewable at:

https://wiki.php.net/rfc/add_str_begin_and_end_functions

The github PR may be found at:

https://github.com/php/php-src/pull/2049

Hope to be hearing about this,

Will

Firstly, the argument ordering is the wrong way round for a string
function. String functions — especially search-related ones — are
haystack, needle (see strpos, strstr, strcspn, strpbrk, etc).

Secondly, I feel like this RFC does need to include that it’s a BC
break by introducing new global functions. A quick search shows that
SugarCRM[1] already implements str_begin and str_end functions and
there’s likely to be other projects that do too.

[1]:
https://github.com/sugarcrm/sugarcrm_dev/blob/ae189cfa4ed4edd6a4e1e0d9d1d5ec66f46a0b74/include/utils.php#L2082-L2090
--
Simon Welsh

You are correct, functions like strpos and strstr do follow (haystack, needle) but functions like str_replace follow the format (needle, haystack). Because I did these functions with the underscore, it made sense to make the functions follow the format found in other str_* functions. If the functions were changed to be strbegin, stribegin, strend, and striend, then it would make sense to follow the (haystack, needle) format. However, I think adding the underscore greatly improves the readability of these functions. And if the functions are named with an underscore, I think it should follow the format found in the other underscore functions.

Good call on the BC break, I had not thought about it breaking userland functions with the same name.

-Will

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

Reply via email to