Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121389 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48434 invoked from network); 18 Oct 2023 13:03:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 13:03:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD681180504 for ; Wed, 18 Oct 2023 06:03:10 -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=-1.6 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 192.99.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mail.processus.org (ns563681.ip-192-99-44.net [192.99.44.131]) (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 ; Wed, 18 Oct 2023 06:03:10 -0700 (PDT) Message-ID: Authentication-Results: mail.processus.org; auth=pass smtp.mailfrom=pierre-php@processus.org Date: Wed, 18 Oct 2023 15:03:06 +0200 MIME-Version: 1.0 Content-Language: en-US To: someniatko , php internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Subject: Re: [PHP-DEV] Custom object equality From: pierre-php@processus.org (Pierre) Le 18/10/2023 à 14:50, someniatko a écrit : > Hi internals, > > 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? I'm not fond of operator overloading, I actually quite hate it, I like the expressiveness of an equals() method. I would very much prefer to have a set of standard interfaces such as Comparable { compareTo($other): int } or Equatable { equals($other): bool; } which the standard API and userland libraries could make use of. In all cases, I don't like the ~= choice because in my mind it literally translates to "is approximately/barely/maybe comparable to". By the way, please  do not use abbreviations such as WDYT, I'm not a native english speaker and I don't know all abbreviations, I had to duckduckgo' it. Regards, -- Pierre