Re: RFC Posted for str_begins and str_ends functions

From: Date: Sat, 13 Aug 2016 23:17:01 +0000
Subject: Re: RFC Posted for str_begins and str_ends functions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-95126@lists.php.net to get a copy of this message
> On 14/08/2016, at 2:47 AM, will@wkhudgins.info wrote: > > On 2016-08-13 04:34, Simon Welsh wrote: >>> On 2/08/2016, at 8:52 AM, will@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. str_replace and str_ireplace are the only str_* functions that don’t take the full string (haystack) as the first argument. str_pad, str_repeat, str_split and str_word_count all take the full string first even if there are other compulsory arguments. Also, these functions are replacements for current usage of strpos/strrpos/substr_compare, so I feel like the argument ordering should match those rather than another function that isn’t closely related in functionality. > > Good call on the BC break, I had not thought about it breaking userland functions with the same > name. > > -Will -- Simon Welsh

Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
« previous php.internals (#95126) next »