Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128576 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 A62391A00BC for ; Wed, 27 Aug 2025 16:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756313730; bh=xFxjz9sZ72QSj4qDLvHmVsvX4JDtrh8SBZZVNqvLTlk=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=eBN3FG/FqLW8t7ZMhXHXQBLb7nMk+TH281bvDuidGsI4OR6S3m1a5mL+CzCix/pVa euDREIxFeeP/CBKsWuggAZSO2xMooNL1dqhPUO7A+aKsaN6ZmRhvDjKdBtltykwx3c XdwolSRJNhwr3IpOYstMqRI0E3CJzAV065IZ54IudBD1QRde8sDZ2z5/llkckANxjk 5oBN0h8D5poy3K6t9ZYVIJ9RPOXW7o+neqC9CcaegNHHcJAVt2HDugtKQ3kl7+NGL1 W7dAvN1UOiUtknn+l8bqI0RTH7gLWh2UHn70R+P64AZUQ0D6vE1ffVYf5kPCrYhJ5K ZdgL/DZ7dlebg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3957B180059 for ; Wed, 27 Aug 2025 16:55:29 +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=2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MALFORMED_FREEMAIL,MISSING_HEADERS,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-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.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 ; Wed, 27 Aug 2025 16:55:28 +0000 (UTC) Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-89239afc84fso2017539241.3 for ; Wed, 27 Aug 2025 09:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756313820; x=1756918620; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ts4fDv286HFm+BFGJIKam6migKwCEQN5DolqZ235RRI=; b=bGgtJM84dNL4h4CiqlgirL6WyqSK2an7kXqjfwLNSmxBluSF4ZkqxSA2fEwxHDh+74 qzFYAE0NHomAGvnmQdnH1WyzT5LC1BJCq1U/lHsHnInsrEz43O4WdlCDyFfl9SbzYbsn 8RKyPkBbD8RlmmLF+r/cUwmBLRtzTzP2FZa19dPfa3m8SZUztNgLzjto5icLH/HyoeYQ jvtt/r1CWUjAJ29o3u3woAy5i308KiBFxPnmUgZsyWV3wdfnz4aJJ62WBklNwUj2TItr jK96SVvfmf9qsX5De2CFsLUgIWrGNpGEKwGN67shJb+ftdvRheEUcLXkpazkhwENz+kJ M/uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756313820; x=1756918620; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ts4fDv286HFm+BFGJIKam6migKwCEQN5DolqZ235RRI=; b=HEkFkRaTZU3fweEt1A2xeMzPGHHN/lX0RdLZ5iuAUW8EoRHZxFCg2UYdBB8R/y9hSZ ZgXSK0W10tcTxeJBqYOmjlt+VL53d4DO93RgD3tG/oMzX+89/IVfKQv4PVFwzmgxtK7P 8emiWMHdi3i6pe1mXvt2WZVkAsuxOKk+aOUYWJnQQhD0bhAgCAmFpAuql62d3O7wZx56 bR9vzoMAy5/hlRbuuqDRgCKGmmfgK3vypHjkbYmWMvdHrTHKaESJdAD6vSKbZyAwC1Th qqhskueOi6AFun8ius0tz0s7La1oeuWtDk0g84MC2fdmj8KuN5yNzLOgY9zUrFl900To fLKg== X-Gm-Message-State: AOJu0Yz8bkl9DxbjKM3AypNp0iZAqzjXryGlPmrRQRXlxiDNurDkbmmy 1m4c8ItGnbeYvS1nHmHw0xhpKI4oeBMJNQWn4SpY2+FvP5JmEad7mTXZX7j6tbxs0fUTyfKIKFE yDEbVRpbUBVAAbFeT6gXiHVp1Cx0QLQ4m4A== X-Gm-Gg: ASbGncs7TVQKpqCSSoXRgHrK8i6ifpUiYpcVBk30p+l6uunHSSTdTg9UfOWykwy50X/ 8cPk7HdN772TkrtwczI43tnD1Nq7ueS76LOUuCiiD0/s7PtgtBNTo4BANJEPf2YTkSAadvtcqm7 WKraTp9kdnTcM4Q/8AZomDw18ecbARpBbiWBlxT232iEncH43HuMo8AZarF3ZYX4j/bgb4iI+J8 8qidU4LEP1SLsfr0iZkSMURe+wAjlyZkd3FjieHBeMQ+W8dHMNk X-Google-Smtp-Source: AGHT+IEjlwUtLkf7y2iZhYqd4tTHmhnmdmIoD5rTilPAUO2CmCzwrZbVFHPlGKMTMC1LesWk8XBBzKl7+KufD2pAvwE= X-Received: by 2002:a05:6102:6112:10b0:51a:4916:c5ec with SMTP id ada2fe7eead31-51de96cb1a0mr4454123137.28.1756313819864; Wed, 27 Aug 2025 09:56:59 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <090b74db-6e29-489e-870e-4c1e336c7746@app.fastmail.com> In-Reply-To: <090b74db-6e29-489e-870e-4c1e336c7746@app.fastmail.com> Date: Wed, 27 Aug 2025 12:56:47 -0400 X-Gm-Features: Ac12FXy5skfqVS63NepODIN0vwYcAVYRIsnsmmgkJJhumVAx9QVBrbI1t8qlGGY Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add clamp function Cc: php internals Content-Type: multipart/alternative; boundary="00000000000058e253063d5bad50" From: coderabbi@gmail.com (Yitzchok Willroth) --00000000000058e253063d5bad50 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 27, 2025, 12:44=E2=80=AFPM Larry Garfield wrote: > On Wed, Aug 27, 2025, at 11:06 AM, Bob Weinand wrote: > > Hey, > > > > On 27.8.2025 15:34:53, Kyle Katarn wrote: > >> Hello, > >> > >> I handled the feedback received on the draft RCF > https://wiki.php.net/rfc/clamp_v2 > >> > >> If I didn't forget anything this should be now ready for discussion. S= o > I updated its status. > >> > >> There is an implementation proposal: > https://github.com/php/php-src/pull/19434 > >> And some draft for documentation here: > https://github.com/php/doc-en/pull/4814 > >> > >> Thanks, > > > > > > As others have noted before, what's the motivation of having the > > to-be-clamped value as first parameter rather than infixed between min > > and max? > > > > E.g. from CSS: https://developer.mozilla.org/en-US/docs/Web/CSS/clamp: > > > > `clamp(min, val, max)` > > > > Feels to me as the most natural order, too. > > > > > > > > You mention it was taken from the first RFC, but that one also did not > > discuss the ordering in the first place either. > > Some quick data points from momentary googling: > > CSS: clamp(min, val, max) > > Python: clamp(val, min, max) > C++: clamp(val, min, max) > Java: clamp(val, in, max) > Javascript: clamp(val, min, max) > C#: clamp(val, min, max) > > Kotlin: val.clamp(min, max) (as an extension function) > Ruby: val.clamp(min, max) > > So it looks like CSS is the oddball here. We should follow the clear > majority approach. (Kyle, feel free to include this in the RFC.) > > --Larry Garfield > A reference from userland, Laravel has Number::clamp($val, $min, $max) as well. https://github.com/laravel/framework/blob/12.x/src%2FIlluminate%2FSupport%2= FNumber.php#L301 > --00000000000058e253063d5bad50 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Aug 27, 2025, 12:44=E2= =80=AFPM Larry Garfield <larry= @garfieldtech.com> wrote:
On= Wed, Aug 27, 2025, at 11:06 AM, Bob Weinand wrote:
> Hey,
>
> On 27.8.2025 15:34:53, Kyle Katarn wrote:
>> Hello,
>>
>> I handled the feedback received on the draft RCF https://wiki.php.net/rfc/clamp_v2
>>
>> If I didn't forget anything this should be now ready for discu= ssion. So I updated its status.
>>
>> There is an implementation proposal: ht= tps://github.com/php/php-src/pull/19434
>> And some draft for documentation here: ht= tps://github.com/php/doc-en/pull/4814
>>
>> Thanks,
>
>
> As others have noted before, what's the motivation of having the <= br> > to-be-clamped value as first parameter rather than infixed between min=
> and max?
>
> E.g. from CSS: https://develop= er.mozilla.org/en-US/docs/Web/CSS/clamp:
>
> `clamp(min, val, max)`
>
> Feels to me as the most natural order, too.
>
>
>
> You mention it was taken from the first RFC, but that one also did not=
> discuss the ordering in the first place either.

Some quick data points from momentary googling:

CSS: clamp(min, val, max)

Python: clamp(val, min, max)
C++: clamp(val, min, max)
Java: clamp(val, in, max)
Javascript: clamp(val, min, max)
C#: clamp(val, min, max)

Kotlin: val.clamp(min, max) (as an extension function)
Ruby: val.clamp(min, max)

So it looks like CSS is the oddball here.=C2=A0 We should follow the clear = majority approach.=C2=A0 (Kyle, feel free to include this in the RFC.)
<= br> --Larry Garfield

A reference from userland, Laravel has Number::clamp($val, = $min, $max) as well.

--00000000000058e253063d5bad50--