Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130200 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id CE4321A00BC for ; Fri, 27 Feb 2026 21:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1772227701; bh=yvTC/8DOUvJ3ph6udzWKqg0r5/+1wIOeQexOFQ8wVuA=; h=From:Subject:Date:References:To:In-Reply-To:From; b=WQ8RrZkRemYTYFBvvFhk29gykys6r22phNZ+xEd41EJRSKPFmZ1UgeqeK1oi0Tdew yC0T9GaOhKpX3P6L240cgX/pFDWZMs2D8z9/KcKegxYtU4bez/MOcS59qO6b5xQW49 1alUEP8zrRKIfonyFTzVs7nBuFbF6BTFHjJS55CSlpzY9Iskaw6hgmMyMzaLFsWwQl /ALreYJf0kUvo4Cp9JGr0NDiGtlbzzMjVyUgLR+Tg41FIX7PPS/p0sziCA/yFbIeAc UMR5KQWBdxCQCYb+6v1MKIrrk/oE0bm2UxC0bD5jQ8JNCnGzDO5+RNZzztUqYhMZu7 aKRWBfma21rOw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A5759180086 for ; Fri, 27 Feb 2026 21:28:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail.gna.ch (darkcity.gna.ch [84.234.28.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 27 Feb 2026 21:28:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.gna.ch (Postfix) with ESMTP id C7B122381820 for ; Fri, 27 Feb 2026 22:28:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1772227682; bh=yvTC/8DOUvJ3ph6udzWKqg0r5/+1wIOeQexOFQ8wVuA=; h=From:Subject:Date:References:To:In-Reply-To; b=BKyIAlvfBHef97nhQhggoowaE2nZ7NkjatxSsNVrLbCsByo7/aVA+KKmZHMHzTvda 1Ib4J3QC6PSrQJZnhrFAUc5fV8BfxKpqahl3cD3CPav5JAdIQ5Owr0F1kYUfZ+vHMK /NIJhBp44cj2fMGmKjzA9dyB5EODayFbo6NU+K2g= X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (mail.gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IPc7NzKi-HpW for ; Fri, 27 Feb 2026 22:28:00 +0100 (CET) Received: from smtpclient.apple (unknown [IPv6:2a02:1210:2e2d:4d00:94:7992:c5f9:4088]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.gna.ch (Postfix) with ESMTPSA id C61D12381779 for ; Fri, 27 Feb 2026 22:28:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1772227680; bh=yvTC/8DOUvJ3ph6udzWKqg0r5/+1wIOeQexOFQ8wVuA=; h=From:Subject:Date:References:To:In-Reply-To; b=P+6JEX8i07Iv6SXkml84oxVlOCd8HapBmw9/6CgRWccL/ElMLfaZJ+9282PW9vFvV aXOrc+7pfaJ11+xB+KErf+01SIYkHmPNlxVgfQIm5hLQG8oBApkpnYJBIV0HfSWj8x K/rmvT8aQRj8ErwpEoexn20LQyBKGYvju+lXBehc= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: [PHP-DEV] [RFC] [VOTE] Prefix and Suffix Functions Date: Fri, 27 Feb 2026 22:28:00 +0100 References: To: PHP internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3864.400.21) From: cschneid@cschneid.com (Christian Schneider) Am 27.02.2026 um 14:31 schrieb Barel : > This is to announce the opening of the vote for the Prefix and Suffix = Functions RFC >=20 > RFC: https://wiki.php.net/rfc/prefix_suffix_functions > Discussion thread: https://news-web.php.net/php.internals/129842 My reason to vote no was that a) it is sort of a matrix of functions (prefix|suffix x = ensure|remove|replace) a doing something very similar b) there are several downsides to these specific implementations The downsides I see at a first glance: - case sensitive: str_suffix_replace(".jpeg", ".jpg", $filename) does = not work with "Image.JPEG" - *_ensure doesn't handle multiples: str_suffix_ensure($path, '/') does = not handle "/api//" This leads me to the conclusion that I'd probably stick to the = old-school use of preg_replace which handles *all* the things these = functions try to solve. And while I agree that regular expressions are a bit harder to read they = (to me) are simple enough while not having these downsides. E.g. I would rewrite $file =3D str_suffix_replace('.jpeg', '.jpg', $file); as $file =3D preg_replace('#\.jpeg$#i', '.jpg', $file); # Case = insentive, easily extended also handle jpe and jfif And instead of $path =3D str_suffix_ensure($path, '/'); I would write $path1 =3D preg_replace('#/*$#', '/', $path, 1); # Ensure = one single slashes at the end or maybe even $path =3D preg_replace('#/+#', '/', "$path/"); # Also = normalizes all multiple slashes in the path Side-note: Regular expressions handle all the stuff described in the = Future Scope section. Some people like long and descriptive special functions for (depending = on the context) common cases but I realized that I often prefer being = able to reuse powerful functionality instead of having to guess if a = specialized function might exists even with modern dev environments make = finding the right function easier. YMMV. Regards, - Chris