Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121452 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45960 invoked from network); 23 Oct 2023 16:36:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2023 16:36:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 993D81804D0 for ; Mon, 23 Oct 2023 09:36:13 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 23 Oct 2023 09:36:13 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A1BA05C02CC for ; Mon, 23 Oct 2023 12:36:12 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 23 Oct 2023 12:36:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1698078972; x= 1698165372; bh=HorMOLoYfJfX5zoumUBInYL21sIQXiXb8gjpPwB4U1o=; b=s sseHSb8C+5k7Zd5uFvMtPgYm0rc5VlOGU6wK8orHVg3IRyRvN5dk0wQq4mUT00+T AMiGXEZNQO1dR0yrizCdOG+KX9AAT1Y8GMTSraSSHkQhLakUtQLVFh3wYD7tCClv qhMDn3y3DJ17lW9iMXvyBRH2kwCKxKcsJr2IcjkiuvZ0Svd2FIKVwBIDpPqK9rGy wUOueZV6K7u/cIUC3sY3kizNVtiZU6ubHurF2ESKEtYfw4iqtU64IbOd/Sx8K3T0 i4bPctk9OhJHk8ScUMP9DZWY/vpdOsrELgr6V9PT+7y0VJymrl6ywVzJ3Ft3+M6P QLB1lZ1vHKsOOaX3BFWiA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1698078972; x=1698165372; bh=HorMOLoYfJfX5 zoumUBInYL21sIQXiXb8gjpPwB4U1o=; b=FLRhjofqY1P6SVtnJuSmksgP6pqMG iGjzbGpfy80sdokl24YHL6cqQL0jSJ6ZO9V01VWyAo06OJsWtB/sXqLBAlaJsWTR WwFdofRvcSVa6dywmvwiKySR9wwnYetr5pMPm7rnhLpu/2nrphkWwRpeTbTuriEo 1ygg9pk4ZSZLoMj9TPgGS9GWvAEuGoByCV0tfQM5ByNdAdWdXZ6K/E6KZkyN4XRW kO1QNR/UpqFH5s1ndu/YEIC1VsJG5R5pY7As7HnRsc0hjdi3n7FYd/WmgUOpFaBf 4mPWLFB0YMR9W2u1Svobd0e9VFmeEsnrgIKF/oauOgKyjJuHykmTvOdFA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrkeeigddutdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeevheehvdevjeelvdevgfelvefftdejkeelvdekgeeh fffgiedvjefhhfeltdduteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhi vghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 40E231700089; Mon, 23 Oct 2023 12:36:12 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1048-g9229b632c5-fm-20231019.001-g9229b632 MIME-Version: 1.0 Message-ID: <53753a0f-04c2-442e-821b-20f107313a13@app.fastmail.com> In-Reply-To: <97e67da5-d54a-403d-be4d-ed275240442a@gmail.com> References: <97e67da5-d54a-403d-be4d-ed275240442a@gmail.com> Date: Mon, 23 Oct 2023 16:34:10 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Custom object equality From: larry@garfieldtech.com ("Larry Garfield") On Mon, Oct 23, 2023, at 3:14 PM, Dik Takken wrote: > On 18-10-2023 14:50, someniatko wrote: >> This approach allows combining >> - no BC break - `~=` is a new syntax which is unavailable in older PHP >> versions >> - explicitly showing an intent that objects are compared using a custom >> comparison, rather than standard PHP one >> - allow to skip writing boilerplate equals() methods which just forward >> equals() to the nested objects >> - standardize such comparisons on the language level >> >> Of course how exactly this operator looks may be changed, `~=` is just an >> example. >> >> WDYT? >> >> Regards, >> Illia / someniatko >> > > One thing to keep in mind is that operator overloading already exists in > PHP. And it is already in use in userland PHP too, for example when > comparing DateTime objects. The limitation is that it only works for > some objects: Those that are implemented in an extension. > > To me, the obvious way forward would be to lift this limitation. But... > several attempts to do so have failed to pass. People are hesitant to > unleash full operator overloading power to PHP developers. > > So, perhaps a simplified version of the RFC by Jordan LeDoux, limited to > the `==` operator only, would stand a chance? It would allow the > community to try their hands on this one (highly valuable) operator > overload. PHP 9 is coming and provides a great opportunity. > > I also like the idea from Pierre to provide interfaces. Some people > prefer an explicit method call over an operator doing magic things, > which I fully understand. Perhaps we could allow both? > > Regards, > Dik I would recommend including ==, <, >, <=, >= all in the initial design, as they do interact. I've said in the past that I'd welcome a reduced-scope version as a stepping stone. Jordan's RFC explained in detail why interfaces are not viable, which is why we have to use magic methods (with or without a special keyword) instead: https://wiki.php.net/rfc/user_defined_operator_overloads#why_not_interfaces (Seriously, it has an extensive FAQ. It's one of the more detailed and supported RFCs we've seen.) --Larry Garfield