Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125621 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 571451A00BD for ; Wed, 18 Sep 2024 14:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726669274; bh=3+8Atoze97/Ge0GiRig5wjpLRE1OepmVkmhEszRS+2M=; h=Date:Subject:To:References:From:In-Reply-To:From; b=OQdZ7cYIctwQqkF4ODdRpFX+uagyRop7xvHjRm5InyiPANEPeVjgnjTGHNFji9BJS JcBuikFX0fCO1YzofMXHYV8HinexiVMt+KLZqDZ5Ner8XLR2cYw1zzjjILcreIlfac dGb8s75izD/obsHHROmJvVaSqLXCR8rPsgEe6rGa1/tKbc0lDSkQ8U6SP5nhgCqsh9 PQp8EnjqQEP0LipNgDmDrrnm/TW7wPT4XM8T7w1kGSzFEJKIqOcUb+C/yT5v7WVXw2 1lmxN8reJs7jj43LujqBqiPNn3Hmz48YrbaGG7bDvnpaoOgteygKC6W3kT8HXh+XWN mHKvAL8n+VH3g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 041DC180052 for ; Wed, 18 Sep 2024 14:21:14 +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_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) 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 14:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1726669142; x=1727273942; i=cmbecker69@gmx.de; bh=oj8Xf9TirVzXX0ooTfOhVj84yuUo8b7OPkXlgBagJ9Q=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=H6z3nmC1laaOmyS20CZ7H4ZwHYZzASoyWjxI5eu01wIszpGYcqiMIXH44kNgoztI Ypod0kW2xqplX8y2IwWvsl0GGhnNGGMrn7NYnc6/vrrXvsWqcMKW/H64i+aS2Kb2+ +N8rW4sAHrikPsooC9BBU4dkmpAPNWonOE5i+YNJ1A6wWhBk/6zObqiAwcYhLr67H liBqiPrEnPu4ZmvZTVFNsW+2WoYP0W9iAJcoSNd7rk9S4CBHwVOcEnEXXy4mDUAF7 m8dI25U64iQLLwbEKTqThRA9KFLth3Z/ut2vsS4udGFxQM8/65QUj1SDxqYulFM+h B9eyFYt99X7SyUJirA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.2.130] ([79.251.205.37]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MmUHp-1s923z3KE5-00cVQ1; Wed, 18 Sep 2024 16:19:02 +0200 Message-ID: <3f6d4409-d370-4391-a8e5-a8a50d8da793@gmx.de> Date: Wed, 18 Sep 2024 16:19:02 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Pre-RFC Discussion] User Defined Operator Overloads (again) Content-Language: de-DE To: "Rowan Tommins [IMSoP]" , internals@lists.php.net 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> In-Reply-To: <12de3d03-3426-44f8-a83f-d686d2034912@rwec.co.uk> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:6Vuv0N3LTKXk3w3NWkfnIb3TOAwtl+HOk9DT/H2b8GwGAV91N8P jN+KWlWlG+hyclx2SXd8f/R0ZnTrI+z9Zpvl/O4Oc3Mgw8uTc281o2SNouP3sz0eFBgQnwC FD+6+jfr8iNwYrtuPdnzcJc9r20ImV5z58FBlVnZ9MNG5WNxm67ImMQXxZnLz4G9gvOOWNT 74r9oAW7w5z0VEbqRqS8Q== UI-OutboundReport: notjunk:1;M01:P0:/9CyVvydgn8=;oPnPNefM5/gJEO7M091PaLGIo0t 8LH6PaBs7wO2g0rS5Tv3fr8L45oOWRp7T83sEXJcVDERw093UaEReAX2VxUdUqgIVLe1rtFAq wqi1VBJxgjKVQfC5QO3OLgwbjwrP2IOkhOPHxCBTpPTQ8Ypi/549elnCKi2iUi0ZL8/qSUbFh LBoK9tj8RM0DeOa6OybsR3GjpbUeGCCfHuGNtn0nM45R61iugSnISg850qP0hTZyzTtgSYK7o MeqtBCZIf5YZjEGTYMsQ/DCj6Cp0arKWuf9FaEeB5ExHdCBC8hL09bTbbYQPwSo6hGa4Fqdtq uAFakEr/hxCOzvoOzyUlMEwIJcWg/FCo7rodfjnw6K2/9C0JHNnWqcyl7ex48+dwjZZO+AAZ5 e34zEes9XzfxpqnXOOH5YuHowlrw3uOCo9bGZVYNHrFZdhZen3DsrhAIeEgsZ2Ba0en+XjvVI 8+1ilSNANX59gro0YwsnPVxUsPql3APMvD7uc3sB1OiPp/8R9rv4quX6OsZnap3C+s6wqF2wy xWgT1MRiyatbDFxfUmP7ikjTsiythfvsYyhXYsm74DW6Q7HHhM3A7iy2YI6o0fp7wJzZTb7D0 act29Yl6YTFv7CS6j2fSWDIYTxFcURtD+ptsbIBmN3ow9WkxNBs0v0oEoBJYuSb/M4YYAw3ye rFX9jL6XKanKUpr+Dc+ebBmJiiaXFS1JF1kUY7dfGq0G6zCHXgQQfb02a8WpSXoznx/QTC6// 66RdH7qUfSA7Z0eJBhEbKwI0ZVeYCKSdRqqgXFZ65c4h63bcB3kCI7Wq5x3+/yeOad1nzL1T6 Vg1KPPvY38aiZX8m2GaX2O+IzygneFkeXpGMidV0c0KKw= From: cmbecker69@gmx.de ("Christoph M. Becker") On 18.09.2024 at 00:13, Rowan Tommins [IMSoP] wrote: > Since you mentioned Scala, I looked it up, and it seems to be on the > other end of the spectrum: operators are just methods, with no > mathematical meaning or special dispatch behaviour. In fact, "a plus b" > is just another way of writing "a.plus(b)", so "a + b" is just a way of > writing "a.+(b)" > > 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). Those who want to implement an numerical tower (or whatever) can still implement the operations as being commutative (where appropriate) by doing manual double-dispatch. Yeah, doesn't fit with scalars, but where is the actual problem? And I wouldn't want to restrict the functionality of overloading *exiting* operators. If a library completely goes overboard with operator overloading, either only few will use it, or it might be a fantastic tool of which nobody of us could have even thought of. Now, comparison operators pose a particular issue if overloads where implemented this way, namely that the engine already swaps them; there are no greater than (or equal) OPcodes. However, this already doesn't work for uncomparable values, yielding "surprising" results (e.g. #15773). As such, it might be worth considering to have a separate PR regarding (overloading of) comparison operators. And I would consider equality operator overloading as yet a different issue, since that operation is (or at least should be) inherently commutative. What we have now, however, is not that helpful, and breaks encapsulation (https://3v4l.org/hTR2v); although without that it would be completely useless. Christoph