Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128552 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 4C14F1A00BC for ; Mon, 25 Aug 2025 13:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756129729; bh=22ZiIXI17cnpeLL/uxipIqsMi2zXTIEhWwtrOu345zw=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Ha+tvJ1+L/pX0H7G/WmuM1wxJTGlSS6nLrF6YW9dKNosg0o4mRNkja3M2lTb6+fo4 2MrS9XxOcMfVVUjzO3s7Pkv1f6kerOvNNgi1Ojlpdp4qLWipy/NjU0uaF2IRXRdqfy Fe1uKMGRJliflr2gDOTnOtrRWemFbxpPqTR/tDxUxzAtEHw9YfmmzuNg+1ruZlhYXG bW+aGkTnE2GDkGwh1UwZi7HiibAHIOHtSUzCykhtNeMA4ToO8GNGoca3Fk0ADt622z sTgX4R4xnmSX1rFGKhevhDU5YeVKCmjF4Zv1rLS8bSKukWERZOdXSz9XOpdsDNgP6V pl8b0JcRwuM5g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4397018005D for ; Mon, 25 Aug 2025 13:48:48 +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-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (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 ; Mon, 25 Aug 2025 13:48:48 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfout.stl.internal (Postfix) with ESMTP id 30DFE1D0005A for ; Mon, 25 Aug 2025 09:50:20 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Mon, 25 Aug 2025 09:50:20 -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=1756129820; x=1756216220; bh=8ryYXYy7ORwyvZVqNHrY4 BzZB4jOULU8qQFc4r6258A=; b=kZlhHVZ1zQlvgWqpU6WahXB44U77ulftODmnw Zvi/D/stkuIF9oAyNj/88+aJHzfGWSDbXn63VkVeNsSgykY3NoKKO7IUyXC/HlZZ 32b2Dk5mVkxITBgYtkSkBc2Aqpk40q8PF5SLcrAcBPNd8/GBC093e7uvrxA8rhS/ R4VNLOhRxXR3e2VBj2wq45c4DGOLlFx9L7pQ8lupCDXpVpwaa14HskEna9MvA5lD CIVlKCQbMwOv2yZiYmxaL2GCQjTEEr1w13FfL94W9hHc4PbszRQw8s1nElBmVnIl +r5Ks8GSjze3r7+Oecp5s1hCHyy9B7JKXgyP8ip90rETjkWiw== 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=1756129820; x=1756216220; bh=8 ryYXYy7ORwyvZVqNHrY4BzZB4jOULU8qQFc4r6258A=; b=GYFikwYoGY5Hw+emP uPmzacBUyB3EwOtVJrnbYWR1RLZ4jAJwP8Pt1Mu3hpoqtt5WagTDugUbEo1GFm2+ C6RCeh2+8G6koghtrcHfreTt+iJAu67UHCq7hlZ/MHKKwL+oc/EWRV4L6jM7Zf1B vY822bZdaVE+UtMef3CmuTzY13/FneG+DIaDyqaAotzpJ0PCeRLibnTE87ZZI9HW v411jYp4Ox4/44ahePnn+Pl1HzIUQz1BRMUOaqjGZ4X8cguxjeTwMw2oGGqOqjbs 6uedZ28pnPomPSMW29KNtQJqHX4CLil5Z4Cmb78MLuUyOXstNYiqegOuWVoIDyqZ cgG5w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddujedvheehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdegteeiueegvefhteehfeeffeet udeitdehtdegjeeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghp thhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsh eslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id A705D700065; Mon, 25 Aug 2025 09:50:19 -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: Mon, 25 Aug 2025 08:49:59 -0500 To: "php internals" Message-ID: <9742b754-6544-41ee-bc26-08d48f5c9b73@app.fastmail.com> 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; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sun, Aug 24, 2025, at 9:41 AM, Kyle Katarn wrote: >>> (No need to change it in this RFC, just note explicitly that the exp= ected behavior is identical to that min(max()) construct, regardless of = type.) >>>=20 >>> --Larry Garfield >>>=20 >>=20 >> It only compares the first property, and if there is a conflict, it m= oves on to the next property. That is why some of us have been advocatin= g for operator overrides: because this default isn=E2=80=99t always appr= opriate, as your Point example illustrates. In some cases, you would wan= t to compare magnitude or something else entirely, not just the x value. >>=20 >> What is even trickier is that this process completely ignores compute= d hooks. So, if you add a hook as the first property (for example, retur= ning the magnitude), it is simply ignored. As a weird side note: if you = cast the object to an array, the computed hook disappears, but if you us= e `json_encode()`, the computed value is included. >>=20 >> To complicate things further, the current behaviour for objects is ac= tually =E2=80=9Cundefined=E2=80=9D and it isn=E2=80=99t documented. Ther= e are examples that show how objects are compared, but they don=E2=80=99= t explicitly mention that the object is being cast to an array (see the = above paragraph on why that matters). Because this relies on implementat= ion details rather than documented behaviour, it could change between PH= P versions without an RFC. That makes relying on it a bit risky. >>=20 >> Adding operator overrides would help by making this behaviour explici= t and consistent across versions, or just defining it in general. But wh= enever someone tries to define this more clearly (as I started to do wit= h Records), it tends to run into resistance on this list for reasons I=E2= =80=99ve never quite understood. >>=20 >> =E2=80=94 Rob > > I would not be against operator overrides, though it starts becoming=20 > quite complex when dealing with comparing 2 objects of different=20 > classes. Anyway I will add a note on the RFC about objects to warn=20 > about unexpected behavior, but this is probably out of scope, the same=20 > concerns apply to min() and max() and that's why I added the same=20 > warning in the documentation: "Be careful when passing arguments of=20 > different types because clamp can produce unpredictable results."=20 > Adding a specific note about objects in the documentation could make=20 > sense. Then it would probably be nice if it were also added to min()=20 > and max(). Overrides are their own complex beast, not to be tackled here. Just mak= ing sure the RFC is explicit about comparison behavior (and that it's we= ird in the same ways PHP is already weird) is sufficient. --Larry Garfield