Replying to both Sara's and G.P.B.'s emails below:

> On Jun 23, 2021, at 12:48 PM, Sara Golemon <poll...@php.net> wrote:
> 
> Using some context, I would assume you mean this:
> 
> function str_left(string $str, int $len): string {
>  return substr($str, 0, $len);
> }
> 
> function str_right(string $str, int $len): string {
>  return substr($str, -$len);
> }
> 
> If that's the case, then.... why?  As you can see, the existing
> functionality available is trivial to write.  
> <snip>
> Am I misunderstanding what these proposed functions should do, or am I
> underestimating the difficulty of typing a zero or negative sign on certain
> keyboards?

I can't speak for Hamza, but one reason I can see for why — at least for 
str_right() — is that using a negative index might not occur to many people. 
Hell, I even forgot substr() worked that way until you mentioned it.

But, since objective evidence is better than opinion, a non-trivial number of 
people have searched how to get the last 'n' characters from a string in PHP, 
found the answer, and then went to the effort to upvote it on StackOverflow.  
If the 90-9-1 rule holds, then that's about 6200 people who have been confused, 
searched and found the answer here:

https://stackoverflow.com/questions/10542310/how-can-i-get-the-last-7-characters-of-a-php-string
 
<https://stackoverflow.com/questions/10542310/how-can-i-get-the-last-7-characters-of-a-php-string>

For future people to whom it does not occur that substr() accepts negative 
arguments, or for people who forget that fact, str_right() would provide an 
obvious solution that would be easy to find in IDE autocomplete or when 
scanning the list of functions on PHP.net.  

At which point it would make sense to also at str_left() for symmetry.  

That said, my world won't change if these functions are not added, but adding 
them would be nice a little improvement to daily PHP developer experience.

> On Jun 23, 2021, at 10:52 AM, G. P. B. <george.bany...@gmail.com> wrote:
> 
> All this to say that the burden of maintenance for such a specialized
> function makes it very unsuitable to be in core.

I have frequently heard the justification of maintenance burden mentioned as an 
objection to adding specific features.  And in many cases, it is easy to see 
why future maintenance burden would be a concern.

However, it *seems* in this case that these functions are so trivial to 
implement that once written and documented they would likely never need to be 
touched again. But as I do not yet know the internals of PHP I obviously do not 
know that to be a fact.

Honest question: Would you mind explaining the type of maintenance required for 
simple functions like this?  What is likely to change in the future that would 
require maintenance?  And would you mind giving a few or at least one example 
of a trivial function that did need to be maintained after it was written?  

Thank you in advance for taking the time and effort to answer.

-Mike

Reply via email to