Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102486 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95573 invoked from network); 27 Jun 2018 14:56:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2018 14:56:26 -0000 Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain brzuchalski.com from 188.165.245.118 cause and error) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:40856] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/2D-01794-C85A33B5 for ; Wed, 27 Jun 2018 10:56:14 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 59B98298423B for ; Wed, 27 Jun 2018 16:56:07 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UZhF3kyCGZgO for ; Wed, 27 Jun 2018 16:56:02 +0200 (CEST) Received: from mail-ot0-f181.google.com (unknown [74.125.82.181]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 962342984239 for ; Wed, 27 Jun 2018 16:56:01 +0200 (CEST) Received: by mail-ot0-f181.google.com with SMTP id n24-v6so2503770otl.9 for ; Wed, 27 Jun 2018 07:56:01 -0700 (PDT) X-Gm-Message-State: APt69E3ZM8hVYYYuv01/TyhNTtinBtpZzh5yjLXbRmPVk9R1hw027kFz FW6pgTIHbYVqxw6EWEqXA6T2IlAtqyaY355D1tE= X-Google-Smtp-Source: AAOMgpfbXvNA3twPwJvq+W3rjcKWi2ZiOZdvarEqOLLRq/VmZyMwDZTjc3i3J1iSbWI/av3w1XjeiBDPRQak1x4k/vM= X-Received: by 2002:a9d:3b65:: with SMTP id z92-v6mr3820828otb.388.1530111360210; Wed, 27 Jun 2018 07:56:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 27 Jun 2018 16:55:48 +0200 X-Gmail-Original-Message-ID: Message-ID: To: rudolf.theunissen@gmail.com Cc: Wes , PHP Internals List Content-Type: multipart/alternative; boundary="00000000000017b5c2056fa0d0c5" Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --00000000000017b5c2056fa0d0c5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =C5=9Br., 27 cze 2018 o 03:29 Rudolf Theunissen napisa=C5=82(a): > > I would like to see this in an extension first, i think it's perfectly > doable and people can test it before merging to core > > It was possible in Sara's extension[1], so maybe now also? Take a look. > Actually not sure this can be done as an extension because it changes > zend_operators and introduces a new handler to make it all work. > > > Would be nice if compareTo and equals were used only if left operand an= d > right operand used the same comparator function. > In other words, $a =3D=3D $b must not work if $a->__equals and $b->__equa= ls are > two different functions > > So effectively it means we only call __equals if both sides are instances > of the same class? > > > If $left operand and $right operand both have the magic methods, it wil= l > call $left->__magic($right), otherwise, if only the right one has the > handler? What if the right one has compareTo and the left has only equal? > you probably should add a table that explains which method is called > depending in the availability of the two magic methods in the operands. > > Good idea. :) In brief, as it's implemented right now, the LHS takes > precedence and the RHS will be called if it's the only one that implement= s > the operation. I'll write some more tests for these cases and build that > table for the RFC. > > > I'd introduce a debug mode that forces php to call both > $left->__equals($right) and $right->__equals($left) so that symmetry is > guaranteed by design. > > If we want to guarantee symmetry by design, we have to either compare bot= h > sides or only compare if instances of the same class, or document that > comparison should be implemented such that a > b =3D=3D b < a, etc. I'm n= ot > convinced that a double comparison outweighs the responsibility on the us= er > to be sensible. > > On Tue, 26 Jun 2018 at 21:04, Wes wrote: > > > some ideas and concerns: > > > > - I would like to see this in an extension first, i think it's perfectl= y > > doable and people can test it before merging to core > > > > - would be nice if compareTo and equals were used only if left operand > and > > right operand used the same comparator function. > > In other words, $a =3D=3D $b must not work if $a->__equals and $b->__eq= uals > > are two different functions > > > > - otherwise RFC should specify the precedence. if $left operand and > $right > > operand both have the magic methods, it will call $left->__magic($right= ), > > otherwise, if only the right one has the handler? > > what if the right one has compareTo and the left has only equal? you > > probably should add a table that explains which method is called > depending > > in the availability of the two magic methods in the operands. > > > > - I'd introduce a debug mode that forces php to call both > > $left->__equals($right) and $right->__equals($left) so that symmetry is > > guaranteed by design. You could do that when "assertions" are active. > > > > gl > > > [1] https://github.com/php/pecl-php-operator/blob/master/operator.c --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --00000000000017b5c2056fa0d0c5--