Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125622 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 16E771A00BD for ; Wed, 18 Sep 2024 15:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726672270; bh=UxlGUaxM+r7FmIqXHHR94uXNO2Pjy2wPvBr2mGpiVxo=; h=Date:From:To:In-Reply-To:References:Subject:From; b=BgpYv1/sPgVUzwelm72jwfpgJzBZ1J692weM5L5cHubqYClx8p6S/qxYBS7MZPLEm brJQ6i0QbHiOZmVvFB3bmGkPFHxikwUsqhO3kTUOv4D6BVEmLSziVZC5v3WCZ6dLTO d+Iy4VwzPbT5gzT1P4xHgrexlc3KaGABZ2cPc1kihWUn5soxgMvcrpw9K2cZacHI57 +kOYGIs66ofpqAwm2Y7Izzf9x04BuKqhJaNzOYFmeDuecbuDHE4s0N5Z0rZYLrcQnF qX6Sh6+ArhEMNsUsyc2IdKDJ27Vks2g9DjqXL/6zkcjcz/7bfG1hBy5GOaDVO9YI6k 6XZjgrsMn0XJg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6DAB4180032 for ; Wed, 18 Sep 2024 15:11:09 +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, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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, 18 Sep 2024 15:11:08 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A9D2114017B for ; Wed, 18 Sep 2024 11:09:02 -0400 (EDT) Received: from phl-imap-10 ([10.202.2.85]) by phl-compute-05.internal (MEProxy); Wed, 18 Sep 2024 11:09:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=1726672142; x=1726758542; bh=msMNtGUFcVBjgnqg1mHO3yb+K3/2z0eZq4rz2u28hQ0=; b= rPaV5ud4j53a55iSyH6ZiLePDTpytPUYQaoB0gpm/9/HJI7XlgYxxP1yt9xGv3X7 a8goPsfZFXdYuuMwVPYtO6yzbUTaaxDPa6WgQ4+oJ10R22fO/vXWmoZB2359Tloa 2QIW2+V5dwpDzPSs3RdAV+t6AmGQkRxTX3EgFEZxKaeTbgcBA6OPKInwqcjqQJin nq+ulOXxwD97iVbM8/NvdZmpm2Dr8QJmT/4P3w+rCl9RVLSf36NQrdrPwp1pA4F0 v4/D0EYVYpbLIHzB5Wmgmm1P/JceMv09RCWt2mDP+DqW3kKTulVD/jsJIAZpqDdJ tweNPAcz7UVAQK4JKpxjzQ== 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=1726672142; x= 1726758542; bh=msMNtGUFcVBjgnqg1mHO3yb+K3/2z0eZq4rz2u28hQ0=; b=S eBhUBZkCq7xmaUJphrwmv1s/zKc1x8cRSXlJC7kDlHCBSiQXm4gDkuVLgnIqtEIt 6FgV7t2OwMiRDi4/sYA9F3hqSs7glw5bxNHrYfr4MnbGkHpPcGck4ymZyxglcqpl lEKKujIfaIf+LKiMc0VPxfazCQ8P5A7kNR+371E/alQWE8iFb6k1NsnpQx2qP/vB 3PfsC/ArKVpb2Yq7iUvaq22cWmsfDw9EV7rjbcA2shGHODTe7ElYRvfRyJjsZzE9 PncXkk50Lhu5mGLtcJgTA1RxkaGB+yPmPWEHHl3wkbq1l+XZhkavShM2pej/xPjD QS7GcGovUvn3W8dSrvPxg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekledgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgoufhushhpvggtthffoh hmrghinhculdegledmnecujfgurhepofggfffhvffkjghfufgtgfesthejredtredttden ucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsoh hprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepleevvefhtdev uddttedvudeiudejfeduteehiefhkeetffejhfekkeevhfffgeetnecuffhomhgrihhnpe efvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtoh epuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhi shhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 4280E3C0066; Wed, 18 Sep 2024 11:09:02 -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: Wed, 18 Sep 2024 16:08:41 +0100 To: internals@lists.php.net Message-ID: In-Reply-To: <3f6d4409-d370-4391-a8e5-a8a50d8da793@gmx.de> References: <2551c06a-ec1f-4870-a590-aeb5752fc944@rwec.co.uk> <0f0444eb-8fc5-4c56-8528-5aa528988e73@rwec.co.uk> <12de3d03-3426-44f8-a83f-d686d2034912@rwec.co.uk> <3f6d4409-d370-4391-a8e5-a8a50d8da793@gmx.de> Subject: Re: [PHP-DEV] [Pre-RFC Discussion] User Defined Operator Overloads (again) Content-Type: text/plain Content-Transfer-Encoding: 7bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On Wed, 18 Sep 2024, at 15:19, Christoph M. Becker wrote: >> Maybe it would be "useful enough" to just restrict to left-hand side: > > In my opinion, this is the only reasonable way to implement operator > overloads in PHP. It is easy to understand, and what can easily be > understood is easy to explain, document, and to reason about. I do not > understand why we're talking about commutative operations; even the > inconspicuous plus operator is not commutative in PHP > (https://3v4l.org/nQcL5). There are really three different things we shouldn't confuse: 1) Commutativity of the operation, as in $a + $b and $b + $a having the same result. As you say, this is a non-goal; we already have examples of non-commutative operators in PHP, and there are plenty more that have been given. 2) Commutativity of the *resolution*. This is slightly subtler: if $a and $b both have implementations of the operator, should $a + $b and $b + $a call the same implementation? We can say "no", but it may be surprising to some users that if $b is a sub-class of $a, its version of + isn't used by preference. 3) Resolution when *only one side has an implementation*. For instance, how do you define an overload for 1 / $object? Or for (new DateTime) + (new MySpecialDateOffset)? It's possible to work around this if the custom class has to be on the left, but probably not very intuitive. It's also worth considering that the *resolution* of PHP's operators aren't currently determined by their left-hand side, e.g. int + float and float + int both return a float, which certainly feels like "preferring the float implementation regardless of order", even if PHP doesn't technically implement it that way. Regards, -- Rowan Tommins [IMSoP]