Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102605 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91266 invoked from network); 5 Jul 2018 14:27:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2018 14:27:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=rudolf.theunissen@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rudolf.theunissen@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.44 as permitted sender) X-PHP-List-Original-Sender: rudolf.theunissen@gmail.com X-Host-Fingerprint: 209.85.213.44 mail-vk0-f44.google.com Received: from [209.85.213.44] ([209.85.213.44:34826] helo=mail-vk0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/32-55607-1CA2E3B5 for ; Thu, 05 Jul 2018 10:27:15 -0400 Received: by mail-vk0-f44.google.com with SMTP id o202-v6so4976536vko.2 for ; Thu, 05 Jul 2018 07:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=+1+rnXeHYu0nBWFeH/uakfBoe8F3g3tnBpp24v+P4sA=; b=cHwj4FDoIGRVucIEm+TzodOqpqTm1Ri87Y3DPdNa5m+sGj0nm7G37hqaKa2Ty1B0HJ hJ218JRUIAXuH66AfkG9qK09g4HXaGGWyDPn6Xt4kg9GneXkyxhiRtn7kW3iP7pAS3gX tE5IlFWu3INdGeffBUhcITdAoKmNNL3manOTRrDbIbplU7xvMlU8oG4sRw4Xky3cRfSh Z+QcgWBZLUbSx41HSjrjpW1H52oAh7II+m/F2yd+g5gt7KBMV2TuioVvTXpKq5Q4te0K enNSokUseaVwrW6fRbvh6+UUl/s/5XKD61sPtvhWT3LE0RVyIypOVhsHR0JSFPMhI8Hn NY9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=+1+rnXeHYu0nBWFeH/uakfBoe8F3g3tnBpp24v+P4sA=; b=PQe8S7NbFUqtqooL7JHv3vK+KWZ0ltjW2mV3RB0qWWebQB0O/S9W6oesuuyF2Ek0xx 20OcHIWRiP0n0eVlTBfI5RmzxBDiG+Kx2OrMSN+Ilpbu4DiLLGTQD9wqgbzIu5bKuVTJ Sk5j4YfZdvD8jrk7fVA+Zj7YRCnnrQK/jB+Kd4QPZbKzMGdTA4FMEQ/5jhKuVQAVtTH6 BuLJoLqTstHFCl8C1iX4HubEcL67BJvKseuhtijWWjo2QTBYuOzOrntX3PSvZEuWk73v iK1tY27DhEpIeazZ//4ss5OxU0HSGsCS7G8/lHTPp6+XGeJ1lGZpdrRq0BoI0tzN1g8+ lFzQ== X-Gm-Message-State: APt69E03JpUUU+mPu/tvULn4xhE9134wdQj3WZH8J0FWUI4ie4xPo0rT wKEadsVcHg8vTDDLECWC+lcCTZP2V2swVCupmjc= X-Google-Smtp-Source: AAOMgpfW71aSmEBUj3OqaXVA47P6MWx8uU5FlXRgJ3ei/M9CKVNyyVo5GVBZgvGRXDEZkbL6fIz/5SFcdF6wushVi3Q= X-Received: by 2002:a1f:3cc5:: with SMTP id j188-v6mr3431852vka.156.1530800830922; Thu, 05 Jul 2018 07:27:10 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 5 Jul 2018 10:27:00 -0400 Message-ID: To: netmo.php@gmail.com, Stanislav Malyshev Cc: internals@lists.php.net, levim@php.net Content-Type: multipart/alternative; boundary="000000000000bfc50b05704157e0" Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: rudolf.theunissen@gmail.com (Rudolf Theunissen) --000000000000bfc50b05704157e0 Content-Type: text/plain; charset="UTF-8" > > We can just define that == calls __equals on the left. That's, for > example, what Python does. This would produce a weird consequence of $a > == $b and $b == $a not being the same, but that's what you get for > overloading operators. That's why overloading operators is not always > the best idea, because of disconnect between perceived semantics (math > equality operator, which is symmetric, reflexive and transitive) and > actual semantic (which is not guaranteed to have any of the math > equality properties). Invoking on the left would break the symmetry of $a == 1 and 1 == $a. The current implementation considers both operands but LHS takes precedence. I think that this is the best approach so that the order of the operands should not affect the result. Of course, when comparing two objects, that would only work if their definition of equality is consistent. Honestly, unless it's an implementation error on the user's part, I don't see this being a real problem that would cause confusion or require workarounds. I know this is talked about in detail in the RFC but it's worth repeating here: the intention of this RFC is to preserve the semantics of the operators. Operator overloading is an unavoidable side-effect of overriding the behaviour that the operators are semantically attached to. In any case, "the same class" would be too restrictive, as there's > inheritance, so we should support LSP. But then again, if $a and $b are > in different places on inheritance hierarchy, we can can non-symmetric > operator. This is kinda deep problem that is not really working well in > most Java code, for example. See: > https://www.artima.com/pins1ed/object-equality.html (for reference, > Martin Odersky is the guy who did Java generics, and designed Scala, so > he knows a quite bit about OO things :) That was a great read. A lot of these problems seem to stem from method overloading and hashCode implementation - neither of which are problems that we need to consider here. The bottom line is that there will be the potential for asymmetry, I don't think we can avoid that without a lot of restriction or double-comparison. Somewhat related, and in response to Levi's mention of it in this thread, I've added a frequently asked question regarding Python 3's removal of __cmp__. Please see: https://wiki.php.net/rfc/object-comparison#why_did_python_3_remove_cmp_in_favour_of_rich_comparisons ... --000000000000bfc50b05704157e0--