Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115113 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74224 invoked from network); 24 Jun 2021 11:34:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 11:34:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A3261804DA for ; Thu, 24 Jun 2021 04:53:28 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,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 mout.gmx.net (mout.gmx.net [212.227.15.18]) (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 ; Thu, 24 Jun 2021 04:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1624535605; bh=xuI+gSWjmiZhqHflnEOQWBTj9tTn8syOcmRMafXDRoo=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=BPVq3d9kRb8hIbkP1LkyGM6C63kIaOhDIdFWP/yVllYa8K4EUINQly8nhZfQzT8LI hxq3dszmPEWWBMDyUXUcg4KejO0HF1dYUEuF2hj8oxG2iYX1edH7nI0UMUaCAHj0IC unGYKSkyENyW1Oz3jfg3f81tR1JaK8QRo/zbGiAA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTRMs-1loay13Eke-00TlB6 for ; Thu, 24 Jun 2021 13:53:25 +0200 To: internals@lists.php.net References: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> Message-ID: Date: Thu, 24 Jun 2021 13:53:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Provags-ID: V03:K1:zRO0ziI9JPMUnfy1b4C8vxeoYy7/VdHuqDFPIa42OnqX5VK5RT9 yFpk865Hjx2JagY4nGmXvYZzDHMsPow5GjR1OxstDyTa/zgUCAlQlkpzWMWAjaerDhevULe oSdlq2A+9tq2LdnI6+qoRps2WdHn5iMlSLU4maf9nr0H2oBldr8eAVCEwxiNi57VIhJs1kL IsZVEApm7afn6T+NYb/sQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:l12wiwm1ULg=:NhlAj7hmEPmtDwJOHtNdcw dAukhUCPlSgNBPUF8d13QP2CEiKdHMcX2KxU60oNt9G7wzuGbjPJWk2p3P71NhknRjWZC4uuh 0mErGioHVGts/CORE582Fxz05JcGQ8zsOFdP0Drm+/ASG1o4gb0vHKoOMYmv0VVHPoThsCemt FfdEEsawbYkDjjY4yj4iC/T51+uqGpuUEKm+ieHd8g5Z3O4GGmiMlEWCumaBYKhbrzrjt1+y+ 3chqc4SXxm5lRlEZviY87l9ltvwIbCSr0tgh11eaXRaXbzBRFrggN7d1vfWUZRZr50dU/c9G7 hYHjtoWRjx2ju8jJfrQLn+7pGPthNV0H9M81owyj5iAQwzRgjkLjCdgkwp+r/SOewXpsphT/2 8UUAplKdqV5HH7ToX757bXA6yIDIZ3SqplxeuidU5K4jbQOyIkGWpmkdJpTYddAunxo+o9gkb yPqpLoGGB5+T82WLR5WQEVNbWHfTmeGDW/GXDytC/aP/KFvXaTElFK9DdSOKA+dKuzYVvBWBP rZkpEcGEsFRI9N8tdNeJwxj+Mn4HaInpFZ9ej3T8gC8RwPG1l3i9QOYXKCxMrqIATI26enpdX ZjZWv8ab7uFJaiFkZNjUQeJdxhLMKafMVBef4Lk5doelI+zJVzEPuoqg1vwUQtXfoaD9ayX7l Fsfevk3AFe4cu2n/vFg1l1+ahwd2VDGBg2ukKv88N+y5Jn78SB52J2WNUSxDz4c8TG5gJNqTo DF5cO6gefWV0hOKuTUjyWCNfzA5XKMJa5jCqLjphMrltiFc4lm9y1q5y67k1wSwbu04/41nDw UHm2hbRpNb7DqRksMifY3izOYOvoUGOeeL9ErvRLczts50cwBoZOyCZQIyj1+MJgeOK4EcxsQ LnQGZV4xidyo7V7pm0KlsT5Razi+N1GZBzXQxspJqRW40Q7CLwLSeQzcD+8Uk9KnL4kpfxdwP 5zS6xKL82v1XRMsv77YOgrPMnMtcYKiiLhx6ifTOKB8cn7nJoZJyVS+W0si51jV1QIEJ+KM8+ XXnq1XBaIpkp2sMPoJNlvYvA38N4y9UV0cibPpVNEouJYh25KIRNPWmGxt6WWD/XduY5RPuZU q9Ck1HGvZvC+vY5rcPEFSAC22ds3v7DCS49 Subject: Re: [PHP-DEV] Introduce str_left/right In 8.1 From: a.leathley@gmx.net (Andreas Leathley) On 24.06.21 13:17, Kamil Tekiela wrote: > I am against adding these functions, but for different reasons than Sara > and George. > If we add str_left and str_right then there should be a corresponding > variant in mbstring. The byte-string functions are rarely useful. Adding > these functions to mbstring unnecessarily complicates the extension for > little to no gain. > Another point is that if we decide to add them, then we will bikeshed > forever in an unresolvable manner about the name. Should it be called > str_left or strleft? Current functions don't have a naming convention, s= o > using either variant will be wrong. > Personally, I find substr to be more clear about the intent. I know that= I > am asking for a part of the string. Whereas str_left doesn't convey an > action immediately. Without knowing its purpose I wouldn't know if it wi= ll > pad the string from the left, strip characters from left, or take the > leftmost part of the string. > Don't take it the wrong way, but I think it's a waste of time to impleme= nt > a function that doesn't even need a polyfill in the userland. str_left / str_right also seems very unclear to me in terms of the name. But I don't think naming new string functions in general should be difficult - the recent string additions have all started with str_ (like str_contains, str_starts_with) which seems more readable than any of the non-underscore functions. I do think the intended functions can make sense, just because I find substr to be a bit obnoxious - with a necessary offset and an optional length it rarely is obvious to me at a glance what the intention is, as you can do so many different things with it, because offset and length can be positive or negative, and then very different things happen. These new functions are quite similar to str_contains or str_starts_with for me, in that you don't need them, but it makes code so much more readable. str_left_part(string $string, int $length) would make it clear the left part of the string is returned, and it could throw an exception if $length is negative. With substr you might accidentally give it a negative length, or would need to check if a length is positive or negative (if it is in a variable) to know what is happening. str_right_part(string $string, int $length) would make it clear the right part of the string is returned. And if you compare substr usage to these two functions, it might come through how different in arguments & readability it is: substr($string, -3); str_right_part($string, 3); substr($string, 0, 3); str_left_part($string, 3); substr($string, -6, 3); str_left_part(str_right_part($string, 6), 3); If you use substr all the time you might be used to it, but to me I have to stop and think what is happening each time more than would be necessary with dedicated functions. A function like str_contains definitely had a bigger impact than something like str_left_part would have, but it would still make a difference. (By the way, str_left_part/str_right_part is just what came to mind, could be anything as long as it conveys what it is doing clearly enough, which probably always needs two words, not just one)