Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:129601 php.internals:129602 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 3A96F1A00BC for ; Sat, 13 Dec 2025 14:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765636492; bh=qtACzk/ID8F/M6Frl9Gzi5M9/8UojZU/ZM6eST3z1rM=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=Kfunm6HbUKVNCgxe34SdYUXUlwMCVLXDF8RIZSvHb2y7zKF6gLKEtBZTkUGWqOVyD wnTSls5gM9eYaY8HcxAAoqJPUnBKBWJ/o8LuPzCjqBemJtLLBSpyNwYIM/FWzyaT3T u0+GvYxEVe477KJ3tzB99YpNFcvNVevEhJqD54vihh2N/RyGSXb8M6ZZfefD3xQh4A bn/UDr7D9Ol+Liko0OY8/Hgnyx/giSj9c33OCA50en8rAfz95y9N5PklY4A/55wzmB bidgRTc58im0g3KQgYzzKbIgXjbriHB7sdHnv+IOvHVho9Wzyl91aGLUXfLzCDKiCo DzLuTKnz6NE+A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DF0AC180050 for ; Sat, 13 Dec 2025 14:34:51 +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,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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, 13 Dec 2025 14:34:51 +0000 (UTC) Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-47118259fd8so21241285e9.3 for ; Sat, 13 Dec 2025 06:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765636485; x=1766241285; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=uvzDB03Wk249q7zj3P4GDiIpzGGG5E9Q5DnQ1QTl8w4=; b=gfxLjJ9JwDXnk4ptLE/flUBv5Pd8sPikRlObDf6tU/hYeiK5f8l57KS4EFhfs/v9WR Ot6gFoLh4zT+hx0g+ZhVraAKoZK2eJCKhzmV4Uc70ljtb93w8cveN6KtTF0F7Eq37NSq bjENaeN0MoOH1aW2PEDQsgl3h2pQCWq6Y3D6dQcsz3CdOOXje4npEkwvRevLk18XTPLZ aZzVDJvDwAlFZ9N37PjQ15/jeva/fPfxzT/weDrtfVO+n02urMkZaVPJ+ox6//u2vTar Nu9jqHKiYkUSI6lCVxtH6VYUQP6fEnmyKdw2xkOzW3sNIJ4VyIxWZZf41915IGIzLO3u U70g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765636485; x=1766241285; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uvzDB03Wk249q7zj3P4GDiIpzGGG5E9Q5DnQ1QTl8w4=; b=WNcbthofdB4EU8GLi8GVrXHXENtV5lWEaEgg9KtJFCSszq9M+zy0Rd/Ab1Gq5bKuFj i+7y0DTVzJWXVjh1Cxmvu4zO45jAlXBLnhB/LfcvaoFtbTROdzT3J+kTmVHElh6Tnl8/ MlxtSn4HHNj7aq4rp/aQolPy+/CFtq4JB0jT+iKRiRVDFI0BFsCCobp9/H6YOqTEO7eX UhNVeV7z+PpuTd3T03LpKSY2m8HViJZd4ZQXZ/mFIekChPPHehzoKtbTfbd4Y0fvcmZ0 tJWlMTIW6I2rafl1MSjqriJrAMGswxsRY0XTNQ8vRrHKwaFZKcQrB9HOP4X547l27wK0 3V3g== X-Forwarded-Encrypted: i=1; AJvYcCUyKpcPNWUuiGkYh/FKrXofiLCz2rgshtsrTCGKOwmZFMnwg7RNnQMyHiFrgFyf165xOEQuTmy1y20=@lists.php.net X-Gm-Message-State: AOJu0YyvqzJKaRHHBJZhbc0HCHJCBie9NwXpEp+R1EYrqfsIRfVjc/R2 MjZAhw0Wn2/soBL0I51cW6xvLZzgrL9z+OSX0mytWFjl/N/tuI178CF7PPW1HSN9 X-Gm-Gg: AY/fxX6+HRninpSYa2cPVdboc7BUVvUoTszOCqKQ2jUThaUkUTxDcNhAeUgkLRi2wIO jnMApVp3AsUYupJzlr+hq5uSuoBMF7DkoS0yHPfGv6Ej9muzqPoqgS7TfazIKjebQZbnBCvX4KA kKTuW291QvlMhXJG5+9jeP9xmGCePLJ9ZCzC3gS+7iYBhQQgTGsu04lJ/3qbpoBhKFimDBN7kH0 pthopa4AglZhto+SMnVtOJsRB9m434Uo4ajmELBQPnNYIZQp+Q7rVQyL8EfVZL9M2Qv+KVHgtu7 okSR/FeGLqd+4/IZZU1dzpbDqpcIvvV9dGdqlKBuC4J5QmMhw8bgr6RWlxm/QMooUNGWW5huwpy y25O360boJshRyOVJLAYU45ZeUI5pXeW8w4vaMJYm4lOK3lO4HAavPHRBMdhGaiTshEreFlKf/I 8i40IXehaTc1uEKvXPBalbSLL9 X-Google-Smtp-Source: AGHT+IF7rytg50aoq4nMTdqfZCSCDfxMjULWIbMz5H6B/0wEaR9UJHs153N0bD4Y26kjRPC1P4oqXg== X-Received: by 2002:a05:600c:a009:b0:46f:d682:3c3d with SMTP id 5b1f17b1804b1-47a8f8c4b8emr56103155e9.13.1765636485276; Sat, 13 Dec 2025 06:34:45 -0800 (PST) Received: from smtpclient.apple ([178.134.17.116]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f71576csm32487735e9.18.2025.12.13.06.34.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2025 06:34:44 -0800 (PST) X-Google-Original-From: Dmitry Derepko Message-ID: <46DCF284-EE66-4C85-A138-BCCBA001858E@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_305B6336-8C89-4437-8F24-7A6448EA5064" Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.3\)) Subject: Re: [PHP-DEV] coerce() function Date: Sat, 13 Dec 2025 18:34:32 +0400 In-Reply-To: Cc: "Rowan Tommins [IMSoP]" , PHP internals To: Hans Henrik Bergan References: <462A7CF0-71A6-4BFA-B5FE-CDF3E0CCA5E6@gmail.com> <232310F3-47A1-4F55-B225-9B4159ACA39E@gmail.com> X-Mailer: Apple Mail (2.3826.700.81.1.3) From: xepozzd@gmail.com (Dmitry Derepko) --Apple-Mail=_305B6336-8C89-4437-8F24-7A6448EA5064 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 12, 2025, at 9:26=E2=80=AFPM, Hans Henrik Bergan = wrote: >=20 > trivial to make in userland. Sure, almost everything is trivial to make in userland and re-use as a = function. > how about making a composer coerce package first,=20 > give it some time, check if it becomes popular, > and if it does catch on, reconsider adding it to core? I don=E2=80=99t think so. There=E2=80=99s no node-js world with left-pad = function.=20 People prefer to write plain php instead of re-using external function = that=E2=80=99s needed to be downloaded and correctly loaded with = autoload. Too much effort to re-use. Moreover, event if a function is quite popular, it doesn=E2=80=99t mean = it should be bundled: `dd` / `dump` / `u` / any Laravel global functions = that=E2=80=99s users think it=E2=80=99s bundled. I think it=E2=80=99s better to grep the world with structural search and = find some cases: - condition($a) ? $a : expr() - if (condition($a)) { $a =3D expr() } With more or less popular use-cases: - $a =3D=3D =E2=80=98desc=E2=80=99 ? =E2=80=98desc=E2=80=99 : =E2=80=98asc= =E2=80=99 - $a =3D=3D =E2=80=99true=E2=80=99 ? =E2=80=99true' : =E2=80=98false=E2=80= =99 - $a > 10 ? 10 : ($a < 0 ? 0 : $a) - max(0, min($a, 10) - in_array($key, $values) ? $key : $default - array_key_exist($key, $values) ? $values[$key] : $default - isset($values[$key]) ? $values[$key] : $default - any similar It could be done if I prepare RFC and it will be necessary. Firstly, = I=E2=80=99d like to discuss the idea itself. ---------- Best regards, Dmitrii Derepko. @xepozz --Apple-Mail=_305B6336-8C89-4437-8F24-7A6448EA5064 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Dec 12, = 2025, at 9:26=E2=80=AFPM, Hans Henrik Bergan = <divinity76@gmail.com> wrote:

trivial = to make in = userland.

Sure, almost = everything is trivial to make in userland and re-use as a = function.

how about making a composer coerce package = first, 
give it some time, check if it becomes = popular,
 and if it does catch on, reconsider adding it = to core?

I don=E2=80=99t think so. There=E2=80=99= s no node-js world with left-pad function. 
People prefer = to write plain php instead of re-using external function that=E2=80=99s = needed to be downloaded and correctly loaded with autoload. Too much = effort to re-use.

Moreover, event if a function = is quite popular, it doesn=E2=80=99t mean it should be bundled: `dd` / = `dump` / `u` / any Laravel global functions that=E2=80=99s users think = it=E2=80=99s bundled.

I think it=E2=80=99s = better to grep the world with structural search and find some = cases:

- condition($a) ? $a : = expr()
- if (condition($a)) { $a =3D expr() = }

With more or less popular = use-cases:
- $a =3D=3D =E2=80=98desc=E2=80=99 ? =E2=80=98desc=E2= =80=99 : =E2=80=98asc=E2=80=99
- $a =3D=3D =E2=80=99true=E2=80=99= ? =E2=80=99true' : =E2=80=98false=E2=80=99
- $a > 10 ? 10 = : ($a < 0 ? 0 : $a)
- max(0, min($a, 10)
- = in_array($key, $values) ? $key : $default
- = array_key_exist($key, $values) ? $values[$key] : $default
- = isset($values[$key]) ? $values[$key] : $default
- any = similar

It could be done if I prepare = RFC and it will be necessary. Firstly, I=E2=80=99d like to discuss the = idea itself.

----------

Best regards,
Dmitrii = Derepko.
@xepozz

= --Apple-Mail=_305B6336-8C89-4437-8F24-7A6448EA5064--