On Wed, 23 Jun 2021 at 15:15, Hamza Ahmad <office.hamzaah...@gmail.com>
wrote:

> Hello Internals,
>
> Since feature freeze for 8.1 is approaching, I want to request two useful
> string functions that exist in various languages-especially those that run
> on web servers and used in databases. These are respectively `left();` and
> `right();`
>
> Whether it is VBScript or MySQL, these two functions are available there.
> When I learnt PHP more than half a decade ago, I wondered why PHP had no
> functions that provide the same functionality as these two languages
> provide.
>
> Although both of these functions can be created in the userland, I request
> to build them in core for the following reasons:
> 1. They are standard functions in various languages. This article
> <
> https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_f
> unctions)#left>, available on Wikipedia, compares various languages in
> regard to string functions and recognizes left and right functions as a
> general term to make sense of the attitude of these functions.
> 2. To achieve the effect of these functions, one needs to use `substr();`.
> If these functions are introduced, it will be clear on the readers' level
> the actual purpose of the use of that string function.
> 3. There may be libraries that provide with the similar functionality; why
> not add this popular function to the core and make it available for
> everyone
> to use? IT will not require people to include such heavy libraries to their
> projects for such little and useful functions.
> 4. In the recent versions, PHP did include "str_contains", "str_ends_with",
> "str_starts_with", "array_key_first", and "array_key_last" functions. All
> of
> these functions are buildable in the userland, yet they have managed to
> make
> place to the core because of their popularity. Why not these two functions?
>
> If one has issues with the name choice, this is something that can be
> discussed.
>
> This request also takes inspiration from Kim Hallberg's proposal for
> `clamp();` function. His email encouraged me to put my word on the table.
>
> I am positive that senior developers would provide me with the feedback on
> my suggestion. I am also positive that my request will be added to 8.1. I
> thank you all for reading through my message and dropping a word.
>
> Best Regards
>
> Hamza Ahmad
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
Sorry, but I really don't see the point of these functions.
Most other programming languages, by the link you've provided don't have
such
a function and use either a function similar to substr() or offset ranges.

Contrasting this to the clamp() proposal which necessitates multiple
function calls
to achieve the same result which *could* mean a performance penalty if such
a
function is in a hot loop (e.g. Machine Learning).

To address point 4, yes these convenience functions have been added
recently,
but they are *extremely* common and their alternatives were rather confusing
or cumbersome. And even then there was resistance to add them.

All this to say that the burden of maintenance for such a specialized
function
makes it very unsuitable to be in core.

Best regards,

George P. Banyard

Reply via email to