Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115066 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42640 invoked from network); 23 Jun 2021 14:34:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2021 14:34:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DBD621804F3 for ; Wed, 23 Jun 2021 07:52:40 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 23 Jun 2021 07:52:40 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id d7so3947152edx.0 for ; Wed, 23 Jun 2021 07:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BUjCxVrdSM0I1nQfkyT6wVHntjTp9+YeJo8pjoqrkfo=; b=RlylZULsV4KSN6zuYIqjzxFGgwr4ToqCyoE10t5R9QzUZovkhbvevFG/tz89th/hjD 669gUJP1CRNSN5h2NLUiLhDL5CFyl58Rif+lmNa16rilFV1Fm1Bht5mHLpgD2RI6WGrb UK+IS89LLZ8kZ2uBQrl1i6BkahGE5VeztCKcLQtfASDaSscst+DaUGnTGcL6XYrkT73B YXMY6tEbLHg+rTR8pM8ijOZP01G2m3cphKou8XRIPopzFYHQ+L9Xki1abjMJHCEU1FJ0 uDO8ZpPd379iu85cGk8G6MCrRtcIRk8d40JrS1qkwfrkn4282rr11U+t503jAy+speWF Z7dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BUjCxVrdSM0I1nQfkyT6wVHntjTp9+YeJo8pjoqrkfo=; b=mib5bLGrQE4sPsNgWZVLGHpHeUyIGGIFsCGg/IEWqiaOamTSD0AowHwh8kWcULwQo5 hjYPTV/mg+39bbz1sQ8qYZ5Yko2Mkvy9eLGsuUGpNOczvbpLrxMLoyhNUdS7P1JzsZUp AIaQYrK+d3VEroNrg6zEH9MnaE9lKWNaZsX7pgRrZH7b/f4sm0NRAwcdz73krUO+ZEly IcMlBZ6NhmYaNWrisnncU5LZIeIyaJR9pwSFhthcgtLDXq+he0ib0AgmvgMMUQf1spUo iJWVo46GT4kB7c39sQ7v1rTChbuiiWtHcMfnxfQb598nlSknxltN+mq6ea2kgZW7GmSh mlOg== X-Gm-Message-State: AOAM532wTkv659J7iK1+hdbifYlEcsUhojURYnt576KW2z76UrzR1Dky ODMLmR10uDt0wONP32FV10G9M3PlVOFrW1v6BCI= X-Google-Smtp-Source: ABdhPJxASsSp4hT8J720wEHLuR54P5JqCbyvji9L5uYKjrWcBBrLs6YN172TDHznN1R4rZkKe/gth2WshstPqVK0AKk= X-Received: by 2002:a05:6402:2790:: with SMTP id b16mr78431ede.115.1624459958978; Wed, 23 Jun 2021 07:52:38 -0700 (PDT) MIME-Version: 1.0 References: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> In-Reply-To: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> Date: Wed, 23 Jun 2021 15:52:28 +0100 Message-ID: To: Hamza Ahmad Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ce8caf05c5700ed4" Subject: Re: [PHP-DEV] Introduce str_left/right In 8.1 From: george.banyard@gmail.com ("G. P. B.") --000000000000ce8caf05c5700ed4 Content-Type: text/plain; charset="UTF-8" On Wed, 23 Jun 2021 at 15:15, Hamza Ahmad 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 --000000000000ce8caf05c5700ed4--