Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102550 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20221 invoked from network); 1 Jul 2018 21:00:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2018 21:00:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.128.177 mail-wr0-f177.google.com Received: from [209.85.128.177] ([209.85.128.177:40968] helo=mail-wr0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/98-15351-DF0493B5 for ; Sun, 01 Jul 2018 17:00:47 -0400 Received: by mail-wr0-f177.google.com with SMTP id h10-v6so13518108wrq.8 for ; Sun, 01 Jul 2018 14:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:cc:from:message-id; bh=UJ89ekNT0oTDTAhkbZrZ6ZlCX8SPAmh01RU6yGa3jxM=; b=CUHrcs74OQiXKrMUKnJGZUwQB79WSyx2gR3QTU7ghP3fEUpoSRGAYmt2IFjFLpyfod u3W0r4j+pBucHssFBk3WIaM6GcrhQPtii4ZgqypbwRgy3p4u2Nh6noUCLuuO6muBzTIk Z5UFcZDzo8LrmX304PtybPlflfJ2D5z7gwbA7CS6hUTOSz7mhxcuI8jJ/OLbg1t/8iW5 Jr5Z3xdbNvzclnntim7wQX0MwvWrGuzEOQYLrgOoZwPPmR6iNo3X/ZX35PSirgppKuKc JFLnUNe7wjaDZcEHLr1CpQz2Lj1KQ061NPYzDuQzi8PUBxV2ZzG1DllZtGb1O86YgIvG gxhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:cc:from :message-id; bh=UJ89ekNT0oTDTAhkbZrZ6ZlCX8SPAmh01RU6yGa3jxM=; b=CducyBd53igMcQ6Ry0WPz+cttHIgh3MJgo6EsztpiZ5SZb80l5ZkYACnOLF5Jys+l2 lc3QlPOYUC39O0REgpXpywyev4qrRN2NXTYlEsUuHegBXlF3wSCfAeIbz+xdszurGjQY 5AmSG/6xfUmeQJRfRSjLqJwKv0yCXJPn8kQpFNmygbUphgLWr+Fr+kdRXKxBHGIBSFRd S+sKnPFROAEudwZiDr3bK/vKAxCOJIM6wHTRqdJPkQemssM08/ejJ0lDedgvCst3K2bh CAkH2UQSOXsoV9izCvemUx4v5zRtnLMAWunIKZH2DVGugkwc+YO97swkzMiQhjqRL2ur 8Kzw== X-Gm-Message-State: APt69E2YkN4kGvuxgIV7nJ6WDzpnilrLC7h54gjlJLLq7hR5gqPRFzZV EN+u3LYB2YjewVOTf5D10IA= X-Google-Smtp-Source: AAOMgpdM0CW7hkBH+PuRa+NXT81CtPlbNkvrXHCcSvV4spz2x4KZx/MjEAfYH/6Ft7rDRBhkuBmzVA== X-Received: by 2002:adf:9bc9:: with SMTP id e9-v6mr2058420wrc.240.1530478842654; Sun, 01 Jul 2018 14:00:42 -0700 (PDT) Received: from ?IPv6:2a00:23c4:4b86:4b00:8552:9585:7001:e96b? ([2a00:23c4:4b86:4b00:8552:9585:7001:e96b]) by smtp.gmail.com with ESMTPSA id m3-v6sm13876068wro.27.2018.07.01.14.00.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 01 Jul 2018 14:00:41 -0700 (PDT) Date: Sun, 01 Jul 2018 22:00:39 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <91F0875C-74EC-4115-83F9-5E87A02051C9@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: Rudolf Theunissen CC: internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: rowan.collins@gmail.com (Rowan Collins) On 1 July 2018 19:45:03 BST, Rudolf Theunissen wrote: >> >> I think what I was suggesting is that if people in future want to >overload >> the operators specifically, we would want to provide an overload for ><=3D> >> that was separate from __compareTo, so that you could overload that >without >> breaking things like sorting=2E > > >I think it would be confusing to have both, or to have <=3D> not be >aligned >with __compareTo, because they are semantically equivalent=2E By >overloading ><=3D>, you have to also override comparison=2E Separating those is a reci= pe >for >confusion=2E That's the point though: with operator overloading as defined in many lang= uages, they're only semantically equivalent if the person overloading the o= perator wants them to be=2E The most well-known example is probably the C++= operator >> which for primitives is a bit shift, but is overloaded for inp= ut and output to streams=2E If, on the other hand, operator overloading was added but constrained by t= he language to certain return values, there would be very little to be gain= ed by overloading each comparison separately - all the extra overloads woul= d have to return boolean anyway=2E >When you use the `<=3D>` operator, the return value is normalised to >either >-1, 0 or 1 which is consistent with the current behaviour=2E So the >object >you're returning in `compareTo` will be converted to an integer(1) That makes perfect sense to me, thanks=2E Just to reiterate, it's *not* wh= at fans of free-form operator overloading would want, but I think it's the = right behaviour for this feature=2E >One thing that your example brings up is that `<=3D>` is not exactly >equivalent to calling `__compareTo` directly, which would just return >the >raw value=2E Yeah, that's a good point=2E Directly calling magic methods is always a bi= t peculiar, but I think a note in the manual is probably enough=2E Regards, --=20 Rowan Collins [IMSoP]