Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125575 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 qa.php.net (Postfix) with ESMTPS id 11EE11ADE06 for ; Tue, 17 Sep 2024 04:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726547940; bh=MUfBfYiZ8i8lDpnj3DjEqbHulDDcvQEe0ynuaj2kss4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=QIqU5PirBhOtampu1f9J1eF2cem5QNtFw9+Nh1yeiTKi8jfdqwaslNVrRph7raCEr +yNltUqMhU0BbkgBiKZAl+Q1rxvMPDI6UWrFV41pv9Q+Id527PdqUT3u/vR4WDRoE1 vjwcqPAgW1r/yc0J01fa0jXd//s9mx7bUCfqyWH78ZzIrMoA1vvzKjFnHfMbgOr+re Y8NPk8GYYP5pfwZWvI7EG1e3mVWBYX5n80U/JPq9Ygz59KgHFVYcXYZVjFl95q9pPn di6Rp/8+nJB8/NT8jyHS2fNStWij6uCO8D3AkEhKGTdokHSdHcUsaBDYGSrmd0LxUg yhR/w9RW26Ktw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9D9F218006A for ; Tue, 17 Sep 2024 04:38:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 ; Tue, 17 Sep 2024 04:38:53 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id A8C721380475 for ; Tue, 17 Sep 2024 00:36:48 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-01.internal (MEProxy); Tue, 17 Sep 2024 00:36:48 -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=fm1; t=1726547808; x=1726634208; bh=R6n40aStOg0My5UmpDm8p AwhmKe39cYOlGz8Nqow4X8=; b=hKxlanx7MdvXb3xhpTKBSgnwim/Q7FMGkhYu2 Gy7A54vlUWz6dUl5p98mgmQiTH76e/q2pkf9B0RyEwa/4Ind4EiT4JX7TG77Nsxw MQfw85RciOU5MtRscSh0HP7KdmVIzmruGF6O+VMF8eF+CMGoTITs/oTmxH8aMBAn hRFszp4Ovu5GC181tM4CwdmfeyfdPCLa8O9hQeX6MAtysCjuMUuvJoAn8Qf/SIJE 3XBu75RiOWjzov0cnDPqM5445Nv5zb5Yb7IB+c1pYwQ14tMwg8SsB+/gsmYwJ82j oiCLHZDpwcaRKx3jSf51GNzIjmB2LsDlcAyDfV9Q6oNt41ZLA== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1726547808; x= 1726634208; bh=R6n40aStOg0My5UmpDm8pAwhmKe39cYOlGz8Nqow4X8=; b=C PiFDX3Y5vdUwGQtqxGxTRWBlPiImkfVyEhWscWzQOV4Ps7g4YULgyy93nedTV07U ZS923lbOAybmq8nMcqfbWJMUl2AgoFwDFtKH1c7jXfAPx+guBYp9yHWpnVpzt7lA LuwethMsTSdcokxpyiNLpNyJYPJnaQvJHy5RE6B72uL+HhviTTFMAjxX2NhBUYfS ssTalTyj1DHt4npx1Eqn1INBJm4tG1XUIZ6ZGrbHXCKr02kZPw5IBc9pzoykMKKF 1x4mkLFeqn+ZkHESUKE0E63J07Oo8X+0IOU9r0TmxjKqT2k1begIPb6onRTVnr28 EOBlAfRBBfQlivze7i79w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekiedgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredtjeen ucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfih gvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdeg teeiueegvefhteehfeeffeetudeitdehtdegjeeuieenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggt hhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 609D429C006F; Tue, 17 Sep 2024 00:36:48 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 16 Sep 2024 23:36:25 -0500 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [Pre-RFC Discussion] User Defined Operator Overloads (again) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Sep 16, 2024, at 2:47 AM, Jordan LeDoux wrote: > On Sun, Sep 15, 2024 at 9:12=E2=80=AFPM Larry Garfield wrote: >>=20 >> The "multiply by -1 for <=3D>" bit I don't fully understand the point= of. The RFC tries to explain, but I don't quite grok it. >>=20 > > I will perhaps respond with more detail to the rest of your message=20 > later, but I wanted to address this specifically, because I also feel=20 > that the original RFC I wrote didn't explain that well. The situation=20 > this bit was referring to is as follows: > > You have an object Foo that implements an overload for the `<=3D>`=20 > operator. The proposed signature for `<=3D>` was simply:=20 > > `operator <=3D>($other): int` > > This operator did not have an `OperandPosition` argument. The reason=20 > for this was to prevent developers from creating situations where `5 >=20 > $foo` is true and `5 < $foo` is true. Instead, internally it did the=20 > same sort of reordering that the engine currently does. It calls the=20 > implementation the developer defined, and then checks if the object=20 > that the implementation was called from was on the right side of the=20 > operator. If it was, then it multiplies the result of the user defined=20 > overload by -1. Multiplying the result of the overload ONLY when the=20 > overload is called for the right side is equivalent to flipping the=20 > order. So `5 > $foo` is multiplied by -1 and then evaluated as if it=20 > were `$foo < 5`. This is an edge case, but it was an important one in=20 > my mind. > > It would be entirely unnecessary if we allowed the `<=3D>` overload to=20 > know what position it was in, but that would enable lots of developer=20 > mistakes in my mind for no real gain. Instead, developers should just=20 > implement the overload as if the object assumes it will always be=20 > called from the left side of the comparison. > > Jordan OK, that makes a lot more sense. Reading through the text of the RFC, I= didn't catch that it only multiplied by -1 if the comparing object was = on the right. The implementation is fine, but if you do for a second ro= und, making that a bit clearer would be helpful. --Larry Garfield