Thanks for replying David.
Thanks for the questions, its good to elaborate on things some. I'll
address each question here:
1. No, I guess this is my first time reaching out to the community. I
had gone with str_begins and str_ends because it fit some of the current
naming approaches. I could see an argument for strstarts/strends,
strbegins/strends, or startsWith/endsWith. I'm flexible with the exact
naming.
2. I don't think performance-wise it would be a big improvement over
using strpos, preg_match, or substr. However, I think it might be an
improvement readability-wise. Right now people either use somewhat
confusing code, like strpos or substr, or they implement their own
user-defined str_starts function. I think the benefit in terms of
readability and usability justifies the addition of two new functions to
the namespace.
3. This functionality is doable with the current implementation.
However, part of the goal of languages or tools is to make it easy to do
common, routine tasks. Python, Java, Ruby, C# and JavaScript all provide
this functionality. So I am sure people would find it useful in PHP.
4. Right now, the way I have it implemented, it is case-sensitive. If
people wanted, it could be implemented to take an optional boolean
parameter called case_sensitive which defaults to true. I could make
that change pretty easily, if I did that the function headers would be:
boolean str_starts (string $str , str $search_value [, bool
$case_sensitive = true ] )
boolean str_ends (string $str , str $search_value [, bool
$case_sensitive = true ] )
I like the idea of doing that instead of having separate,
case-insensitive, functions because it helps keep the name space less
cluttered.
I hope this has provided some helpful information. Please get back with
me with your thoughts.
Thanks,
Will
On 2016-07-26 16:09, David Rodrigues wrote: