Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129768 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 4C0E21A00BC for ; Sat, 17 Jan 2026 14:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1768660197; bh=w8A1Joof/SoZgtwPu0ixuo+8DyNDfeBJMDjHWeWxwpU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QDHdWu4qTgegTHPCCb6/7L+nmICLSixJJtxDDdsMoaUU9safAae1AgEl7of/JdtDV lKB2Y3fkLlwXmXpQx2qsRkijXAorjiSJrbeZZYwhMnZaLau3IkscWxrkSXraOYA80n DcagyBqqi70pkAZdivhIkSTBCMDo0EdXiChqENop+7LCuLrLE25eREX41ZYgoZ/0iO zXxFCNhxL1r4oJ45b2BSiyhA3mjFZY4ekruV96cYuxW806B7Sk7OBHsnB2FlbT142i w0dg6oOJ1hP8MgReabWjm5uH5GcNqbxYo54flw8TZO/R5Xj4qP2q7smuEsjUOGeHN5 nGdkhqpIEVokg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B780218002F for ; Sat, 17 Jan 2026 14:29:56 +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=1.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,PDS_PRO_TLD,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) (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 ; Sat, 17 Jan 2026 14:29:55 +0000 (UTC) X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id B049B801174; Sat, 17 Jan 2026 14:29:48 +0000 (UTC) Received: from server52.areait.lv (trex-green-9.trex.outbound.svc.cluster.local [100.111.162.244]) (Authenticated sender: yszpovajlk) by relay.mailchannels.net (Postfix) with ESMTPA id 2A7A8800ECA; Sat, 17 Jan 2026 14:29:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; d=mailchannels.net; s=arc-2022; cv=none; t=1768660187; b=DJnSx5aEiJWS2DZZkUudZjbTT8McKbE7eDPlumI/ZW32CT2NrCmIxFLUmGhxMWmkkocZ3A +AHySTM2ierZ8+X9bpYjscdhgtASeYgUYguYLlqxtAtzB0gEw4hW1ysSsNhHLQcSZrhR5n i8sGWauJqqCUmyNK1pvwhK5Gkirykj/zOlVamI02SU+J2QLai/5vtNeLJE2/FvO/jCDD9z z87t1t86FB8l/vYPKn3cAL+ajzX5wqSHcUNQhRvdh5JKq1PElltsWGUxUw/3miYD7nPMBZ 5t0GJyEShvQGVOWoxa8AucETIFzmzLPCm+n+7sbkEMRTtu/LOqcS+kZ53bi12w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1768660187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+F3qR417zT5kFns2oBNYyLgxb+HsXbMe43VIklHIXEA=; b=GAj8Yhoyu6Xc9yC7ObeGEcobT0u1GwJPOckLql/fcRUp8+BETJDdfsI92idPWvIhpUeY97 KtdLlInDEIxQplq22UfCeqAllsQlzUuWk8d7qgBTp/weaHJtZSDCsDbSs7W5pN5zR75zQe PBk/ECgtRk3pEdtWV/FaOKrb6NkJCJWDatjbduXyPsrPF9Lmv/MgYDgNd2ewgIijK0M85v H7TCehWvKUwKyiNyGIKpkRdMu+PHw0olQb2IY++A/3LgRzFFns3YwCwZkL0Vpj3UceW8Hw /MIuhW78opJyPier/geFRqd2JrhNgQVqQAVtDopUl4CtSePtoaNxqvnrJmXxpA== ARC-Authentication-Results: i=1; rspamd-8f4d6bb8d-td26h; auth=pass smtp.auth=yszpovajlk smtp.mailfrom=juris@glaive.pro X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro X-MC-Relay: Neutral X-MailChannels-SenderId: yszpovajlk|x-authuser|juris@glaive.pro X-MailChannels-Auth-Id: yszpovajlk X-Unite-Harmony: 110e4ca6064538ce_1768660187873_1881034269 X-MC-Loop-Signature: 1768660187873:619819551 X-MC-Ingress-Time: 1768660187873 Received: from server52.areait.lv (server52.areait.lv [83.149.95.205]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.111.162.244 (trex/7.1.3); Sat, 17 Jan 2026 14:29:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=glaive.pro; s=default; h=Content-Type:Message-ID:References:In-Reply-To:Subject:Cc:To: From:Date:MIME-Version:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=+F3qR417zT5kFns2oBNYyLgxb+HsXbMe43VIklHIXEA=; b=lhIfZ7ry9GG3rEWHZsfga634+1 HoJkhRKeo7+D4/yHPTUj4T8+ghoVq233YdtD3YlVwsrcsOUcYc99vS/kQURfnlsnjSnpy9M2H+Bez rWtiq6zp1HhlqgEVblfhcri4CNZ4H20HYlmsl5ofIff3+GESwkXAE2cRSdRsqeKbO6x7TiOYXuhkB 97Bkp3Ebyc/Eve+/sA00obCw+G8L33GCXGvB8GSDop7ZWkQxOjpKoV+r4Hb/sDFX36UBiy2MaiFNK 4zW+GXsG3ZgB0liAFqzjwmNTVO/SOuAbdzvKN6nF15DiIIucMDr9fXmGWXxjvvmh8S9/JmG8H5E2h wdaapfcQ==; Received: from [::1] (port=47288 helo=glaive.pro) by server52.areait.lv with esmtpa (Exim 4.99.1) (envelope-from ) id 1vh7J7-00000009QtA-2c33; Sat, 17 Jan 2026 16:29:45 +0200 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 17 Jan 2026 16:29:40 +0200 To: Barel Cc: PHP internals Subject: Re: [PHP-DEV] Proposal for functions that handle prefixes and suffixes In-Reply-To: References: User-Agent: Roundcube Webmail/1.4.8 Message-ID: <787c91d9a060d0fb05a47d2e3243a79f@glaive.pro> X-Sender: juris@glaive.pro Organization: SIA "Glaive.pro" Content-Type: multipart/alternative; boundary="=_6a5f0d8a8a8e01c6a21a0e71aab3f8e4" X-AuthUser: juris@glaive.pro From: juris@glaive.pro (Juris Evertovskis) --=_6a5f0d8a8a8e01c6a21a0e71aab3f8e4 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 2026-01-16 21:16, Barel wrote: > function add_prefix(string $source, string $prefix): string > function add_suffix(string $source, string $suffix): string > > Add a prefix or suffix to a string *only if the string does not yet > have it* Hi, As the functions do not always *add* a prefix, I'd suggest to consider names like `ensure_prefix` or `enforce_prefix` instead. Something like `ensure_str_starts_with` or `ensure_starts_with` would be a nicer fit with the `str_starts_with`, but then it doesn't rhyme with the other prefix/suffix functions that well. Otherwise I can only say that I've had to solve the same tasks in multiple projects, so I'd enjoy such functions being available in PHP itself. BR, Juris --=_6a5f0d8a8a8e01c6a21a0e71aab3f8e4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

On 2026-01-16 21:16, Barel wrote:


function add_prefix(string $source, string $prefix):= string
function add_suffix(string $source, string $suffix): string
 
Add a prefix or suffix to a string *only if the string does not yet ha= ve it*

Hi,

As the functions do not always *add* a prefix, I'd suggest to consider n= ames like `ensure_prefix` or `enforce_prefix` instead.

Something like `ensure_str_starts_with` or `ensure_starts_with` would be= a nicer fit with the `str_starts_with`, but then it doesn't rhyme with the= other prefix/suffix functions that well.

Otherwise I can only say that I've had to solve the same tasks in multip= le projects, so I'd enjoy such functions being available in PHP itself.

BR,
Juris

--=_6a5f0d8a8a8e01c6a21a0e71aab3f8e4--