Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115077 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71425 invoked from network); 23 Jun 2021 18:51:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2021 18:51:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2ABCB1804CC for ; Wed, 23 Jun 2021 12:10:20 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 12:10:19 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id w26so2914931qto.13 for ; Wed, 23 Jun 2021 12:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=oxlJ8epYX/UjvEf6ssS/YcR/7jT6xOLlncoCHUnxC4Q=; b=QGlcgdMr0xflrqTz/gpvcT9tR/cCm0nPobbWxXaGwGj1tmf+UA/NYWgQ4Q8AZ7oEk3 xxLnmWHbm3Vp3xi4vD8Ne/HLUFyrVXk+A9yOmwDjcVxjsQzMeFkhqLRW0P+LZYgjZ/FJ OJYh6sqGKCJ0ihwslQcRTlMPBNWP7K5Rvfm8XRbvovXtaqIG13BgpCpmc5vGhvMzREa2 XQwK1+CsHHeRQoIUH/OPB89pn7IFVlHz/3xRUWnYkebf7QnKgwDPlsLvSVsBqtFSVGPw /sagEdlJrbFW5mbVm9UX7VgKYUG7x5cHT0lWipyYF/NuM38V8m/oIoichW1oLrz1me60 y4Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=oxlJ8epYX/UjvEf6ssS/YcR/7jT6xOLlncoCHUnxC4Q=; b=ZV+jn1C+uGZSy8WfIl/oR55/YM1XvRDXPo2oekSyVdr4dMgB0TSd8BkvgomjC/2i/W MpvK+fypL0yjj9+BKM2+44x5EI8t7r9bErnrW4Zm0jB5hi7/a7OYKNrujrclWMNVoGKE 4DSsrzIaSvarvNxHvrm9mPWiEnj8ZCq5P/Cp8nsNS32VePnGAe6l05ZpIsBE9io+a0uf VP8vNWkKuK0BPkrHgYlARgYX4O1mXPHINOiq0MxthUKKathAfxgxJahxdOmTt1oCNQFP HP+4WQjVi+f+5//L37wHITy6HdboA1SEfov4xYPjZQDf7pyP5Idoq7CiTFema+ymGl4r TWFg== X-Gm-Message-State: AOAM530NPGMMmFAjKoEhvXKLzF/ndzxtrXpQoVVk5T7qL9djHbGWl/xS BAaY2dMRdXn2H+MdhJQwhwx+9A== X-Google-Smtp-Source: ABdhPJxrF1VVVum7IZHmFz3TFuQ6ueKSHsfaiyx9vYPcmu6EjWaPufuqALYu29WLMCOQbNh5xm+7eA== X-Received: by 2002:ac8:70d5:: with SMTP id g21mr1378837qtp.368.1624475418792; Wed, 23 Jun 2021 12:10:18 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id o126sm602050qka.74.2021.06.23.12.10.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jun 2021 12:10:17 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_E4743CA4-1564-438C-924A-3A0F5B9749B9" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Date: Wed, 23 Jun 2021 15:10:15 -0400 In-Reply-To: Cc: PHP internals To: Sara Golemon , "G. P. B." , Hamza Ahmad References: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Introduce str_left/right In 8.1 From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_E4743CA4-1564-438C-924A-3A0F5B9749B9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Replying to both Sara's and G.P.B.'s emails below: > On Jun 23, 2021, at 12:48 PM, Sara Golemon wrote: >=20 > Using some context, I would assume you mean this: >=20 > function str_left(string $str, int $len): string { > return substr($str, 0, $len); > } >=20 > function str_right(string $str, int $len): string { > return substr($str, -$len); > } >=20 > If that's the case, then.... why? As you can see, the existing > functionality available is trivial to write. =20 > > 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 =E2=80=94 at = least for str_right() =E2=80=94 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-char= acters-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. =20 At which point it would make sense to also at str_left() for symmetry. =20= 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. = wrote: >=20 > 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? =20 Thank you in advance for taking the time and effort to answer. -Mike= --Apple-Mail=_E4743CA4-1564-438C-924A-3A0F5B9749B9--