Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128534 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 960F01A00BC for ; Fri, 22 Aug 2025 20:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1755893280; bh=WFutpqzKLdBJtTh6kcn0U7s3yweYfVWWUs3XycT9qkQ=; h=Date:From:To:In-Reply-To:References:Subject:From; b=fmO94UttVAYWUc/Sf40314nHzbBHmgfZ6VEZGT/tKz+jGDyI2ZCZmjeP7QM17m2Ez JHaGmvgnfUFxcrwM6RI31vIA3Tzvxx0NDGrP2HfI+cEL9BDNvU+n5xZR7xhtoTRI1U ch0vst4Zm+9190AmscK96HpP33h07c7hmeXfJQ4XyqxQ5hQQe9EMqyg8tUiW+evIC6 2gWxcomJ80JWTEmmW1WQ2SU2P2xN1X8iCzB9zCs9KpSrgFoA8x3wX64i/g/bhgroyZ e2eadu01ClhRpJgdaxQ+HX2MUsL01v0y0iwcWH+fXQ0aK/g+YOevq6xTq71+gii2GI 60D3MRLXGQX/A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 74E23180066 for ; Fri, 22 Aug 2025 20:07:59 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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, 22 Aug 2025 20:07:58 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 6AA04EC00F8 for ; Fri, 22 Aug 2025 16:09:32 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Fri, 22 Aug 2025 16:09:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1755893372; x=1755979772; bh=MKjQ5Xg/62YiB1m6ncuRy e5cR1lFYj+b/nz1qPwR+Cc=; b=J4uivxIlfA8hjL/QmysX4Zh795nhLW7LG5NOF oPEybSuS/AlAOuNN4gxdjNMLytVbIdkac3MAu5uL5GGXEBiFvS6PG3zPx+DEvodj 57EO36sz1unu8pPoOxtMTROh58YL7uWpgWQOAbDhf6TnVFZDMTKk0ZTtn7Kguwze v2H9Su7FquWUk50LAz/xgcxn2XgBkqWwjaKf3PlrLCVoSXwjkHW/sb5IKLBsVqpF KnDnd1cY3Z61gfzLveBWdIbSKAFTvta4lfqqTkevb5gwP5SJOrQJ0ZxV4xcCusVL oxd3XiI5OBGyH+yvGf84dDjZaKiN6JCX5DQiNSHsP+OQVCmgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1755893372; x=1755979772; bh=M KjQ5Xg/62YiB1m6ncuRye5cR1lFYj+b/nz1qPwR+Cc=; b=XhzG9iFSZw5T8hQ9K 7LKpEfyQvgjEuuqRLjXYeJv8emnkVdKlNyBqQPsvKOBjXVf58f3k94xLzhGbCWya KXkecKhp9a6+ndK1KWc3QOSCWo37QcFNFe563KW8Wip26qiNahr6F0hICDNqmXTi r9vbZtJI6BZCWdMQ5zng0y+tyzgQCk3RJdO6K4GfGZ/ocy0nSrkrZuXNf0UCHYFz mRMZi6IXSqyF/ejsM3zDIHgA12UIt51glkfbCigGSROxH7VCDBCNrwJQ9jbrqxXp mwLK0ZBgLUn0lLVvmTqhDCbhwQ+YLOifPzwaqbcNmmO4FnWjXGBVmYU5v5+VIIi6 oOwSQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduieegieekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegouf hushhpvggtthffohhmrghinhculdegledmnecujfgurhepofggfffhvffkjghfufgtgfes thejredtredttdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrh hrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeekgefg vdevudeffeetuefggedvffdvleegleeuueekgfduveegleduudehudfgtdenucffohhmrg hinhepphhhphdrnhgvthdpghhithhhuhgsrdgtohhmpdefvheglhdrohhrghenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrg hrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 06D47700065; Fri, 22 Aug 2025 16:09:32 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AEQpMGw9UeFk Date: Fri, 22 Aug 2025 15:09:11 -0500 To: "php internals" Message-ID: In-Reply-To: References: <0027ab13-89fb-40b4-991b-2f88a35c2f31@gmx.de> <272c241b-3145-4069-8a6a-9ea877f936c0@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Add clamp function Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Fri, Aug 22, 2025, at 12:45 PM, Kyle Katarn wrote: > About "What determines comparability", it follows the usual rules of > PHP: https://www.php.net/manual/en/language.operators.comparison.php > > So it's equivalent to ($value < $min) ? $min : (($value > $max) ? $max > : $value) and also equivalent to min($max, max($min, $value)) > > About clamp(new Point(1, 2), new Point(0, 0), new Point(5, 5)); > > If Point is a comparable value (simple DTO for example), it should > return $value, like when doing ($value < $min) ? $min : (($value > > $max) ? $max : $value) we could add a test for such case, but I think > that for consistency, whatever currently works in min() should work in > clamp() > > Following the link of the implementation, there is also a link to the > documentation where I already explained the comparison rules following > the example of what was done in the documentation for min() and max(): > https://github.com/php/doc-en/pull/4814 Please make sure the above is captured in the RFC. Though apparently what PHP currently does with Point comparisons in min/max is... weird. I don't even know what the logic here is. :) https://3v4l.org/pTmiV (No need to change it in this RFC, just note explicitly that the expected behavior is identical to that min(max()) construct, regardless of type.) --Larry Garfield