Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121454 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55869 invoked from network); 23 Oct 2023 20:07:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2023 20:07:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCB851804F5 for ; Mon, 23 Oct 2023 13:07:32 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 13:07:32 -0700 (PDT) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6b87c1edfd5so2839836b3a.1 for ; Mon, 23 Oct 2023 13:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698091651; x=1698696451; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OaY6r6d9m9ofAwQUJ/VcTsTJpeBpCrfQeChksF6o4MQ=; b=KRxqMbMLQFgoxq/wNp8HOt14XzzP1ElkHyXUHeCnrmCsa58x5EvURKE2MYWQqvFco6 P0+VcKZ/sbNvm7JB08e5pzwI80OSLi4virm1N5dKyy2Yrq9GOU5CVDFUJrNY1aUOQr3r dccw72IPiMyKetSbJBReL28+WeaxjdxzYlbEBFhh5+DpYMTzEVlYhEq365R6VUand36w Tlph252vGAI7YQXhhtvJp+/SW0Lk9n9VyAfdo8UJAxMBlBeZeCiPCRKFqKokN6A59bhS z0E4QqsY9y0SL+OwRvWQ0HslxF5izwOxEbvVOAlyxexV6anPO0uq+iEN6/x3YtGbaIkS ACHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698091651; x=1698696451; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OaY6r6d9m9ofAwQUJ/VcTsTJpeBpCrfQeChksF6o4MQ=; b=kOzlB+jLSs+jzwZu/QpEk2LaOCh8us7JU2W03jLDqEursVlKdzA6Is3JUw6KxS3Tuv cd/BENR4kLQe/jZ1FXOiWsYgHRaROABWVbio1RJmQJWwzzVzJLwlwGvcWM3BAb/3lkhz sR6AAQC4qdUgldXgiZiccUTgEWR1wM0AGlQa+OWGfObZa4oAoqNGKywA8QkZSpfmfUft sAKToL5Aw7Me8CgI5bvv9w5Fl3tHYvlresJyH2UTdeQ2Ez04xq9Ed1GenMOaeTGB/Bub A7/TrRK//dRVFoEBZYhVvtl8Ei2XG0x/M9ipk81Fn8iBnHpzwvzkmwqciHF9uUKnCi7E 8bjw== X-Gm-Message-State: AOJu0YwzlNvI2c8tiOF4xXNKwSNUgcB0wOnW/cQ2K8uV56GHD+H5afBx BQ1A0MQRH7evJegWm0Wjow3lQ104tq2exWyKt3w= X-Google-Smtp-Source: AGHT+IHQAP/c5cJMIPgmodt+Pj+LE9Dw4ocb9GMnCKIAcpXLVBClrB37rbOTKmN28AjNEkS5MIswZM4eFrzIBTyQ+x4= X-Received: by 2002:a05:6a00:2da7:b0:68f:fa05:b77a with SMTP id fb39-20020a056a002da700b0068ffa05b77amr8561315pfb.31.1698091650601; Mon, 23 Oct 2023 13:07:30 -0700 (PDT) MIME-Version: 1.0 References: <97e67da5-d54a-403d-be4d-ed275240442a@gmail.com> <53753a0f-04c2-442e-821b-20f107313a13@app.fastmail.com> In-Reply-To: Date: Mon, 23 Oct 2023 13:07:18 -0700 Message-ID: To: Dik Takken Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000a1587d060867c582" Subject: Re: [PHP-DEV] Custom object equality From: jordan.ledoux@gmail.com (Jordan LeDoux) --000000000000a1587d060867c582 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 23, 2023 at 10:20=E2=80=AFAM Dik Takken = wrote: > On 23-10-2023 18:34, Larry Garfield wrote: > > > > Jordan's RFC explained in detail why interfaces are not viable, which i= s > 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_interfac= es > > > > (Seriously, it has an extensive FAQ. It's one of the more detailed and > supported RFCs we've seen.) > > > > Yes, I know the RFC, it's a great piece of work! The use of interfaces > as mentioned in this RFC is however completely different from what > Pierre and I are talking about. If I understand Pierre correctly, that > is. The suggestion to include interfaces simply meant to allow freedom > of choice. Choice between using an operator (`=3D=3D`) or calling the > equivalent method on the object (`->equals()`). That may get more people > on board with operator overloading. > > Regards, > Dik > > I don't quite follow. The interface would cause the engine to use the result of an `equals()` function on the object if it implements an interface as part of `zend_compare`? Internally there is no `=3D=3D` functi= on, there is only the equivalent of `<=3D>`. To implement it ONLY for `=3D=3D` = would require a trapdoor of some kind in the `do_operation` handler that would also affect the way the existing extensions work, such as the `DateTime` class which implements a custom handler for the `compare` handler on the zend class entry. This might be easier to do once a few comparison improvements to separate "comparable" and "equatable" are done, but the PR I submitted two years ago to handle that got kind of mired in bike shedding about the implementation and I lost interest in continuing to push it. Implementing the compare handler for an overload requires adding two new entries to ZEND_AST_BINARY_OP because the `>` and `<` comparisons have to be preserved in the AST in order to call the correct object handler. THAT requires updating OpCache and JIT since all such comparisons are currently reordered to use `<`, and though I spent quite a while looking at it, I think Dmitry might be the only person that could really implement that fully. At least, I never found anyone that had the expertise to actually help me with it. Jordan --000000000000a1587d060867c582--