Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102366 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56431 invoked from network); 22 Jun 2018 11:31:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jun 2018 11:31:44 -0000 Authentication-Results: pb1.pair.com header.from=rtheunissen@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rudolf.theunissen@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: rudolf.theunissen@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-ua0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:35507] helo=mail-ua0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/5C-32156-F1EDC2B5 for ; Fri, 22 Jun 2018 07:31:43 -0400 Received: by mail-ua0-f170.google.com with SMTP id s13-v6so4078118uad.2 for ; Fri, 22 Jun 2018 04:31:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ci2Je8gJOxXzZQ7f9F45qgCoDCUyYBb5xZytRCB6BeQ=; b=dqm1cGjldPbwGFL3py8qsWoiHGB+A6z3Vbq4g/AVNfNTi5uH9nzsFB1z0/RrR8W6C9 kLnkvJs1M5/n9IYUxUifgQ/YFVrXoZdmFDh7usxGi6kthSXT8ZRSk5wTOjz99kDS0am9 sh4bQ56EpSZg60EFooLopHsaJcSlULiBOzpYH4RdPi5jZPiEbE8QDKTpczwIfIkPEI6a 5ydx97d8rnK5dfrUmCxAjVMy40AWM5edJmfrnWfrFDI2afrRCCGq+5djdyMHWAx8RnGG I5xrF9iiOnclhx74j3IhUlhJf2KC7sY0CYgCvqvc0IMWDrpAMnyuA9KEyQIu8VYMrQ5D W4og== X-Gm-Message-State: APt69E0Dv4FPfY/zJQIBNKjD/3loEqDLVzPLy2ij11GbShu6XXTGIZdX VVjNwe6cn5MLC3oBXV1u+R3WDqM+ X-Google-Smtp-Source: ADUXVKLheqLsJk0t439Q4kiHHB2y7XAyRdI1rfmyOSKQc3Lq0bBbBIRzDOKoMemkg7mkuUwT/F3nZg== X-Received: by 2002:ab0:1b4b:: with SMTP id n11-v6mr751501uai.148.1529667100474; Fri, 22 Jun 2018 04:31:40 -0700 (PDT) Received: from mail-vk0-f53.google.com (mail-vk0-f53.google.com. [209.85.213.53]) by smtp.gmail.com with ESMTPSA id e84-v6sm1985747vke.12.2018.06.22.04.31.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 04:31:40 -0700 (PDT) Received: by mail-vk0-f53.google.com with SMTP id o17-v6so3722061vka.2 for ; Fri, 22 Jun 2018 04:31:39 -0700 (PDT) X-Received: by 2002:a1f:df42:: with SMTP id w63-v6mr680810vkg.172.1529667099769; Fri, 22 Jun 2018 04:31:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 22 Jun 2018 07:31:28 -0400 X-Gmail-Original-Message-ID: Message-ID: To: danack@basereality.com Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000001b40a3056f39606f" Subject: Re: [PHP-DEV] Equality and relative ordering of objects From: rtheunissen@php.net (Rudi Theunissen) --0000000000001b40a3056f39606f Content-Type: text/plain; charset="UTF-8" > If __compareTo($other) gives 0 then there is no justification for additional method. > IMO you're duplicating functionality here. I tried my best to explain that this is not the case. There are perfectly logical cases where two values are not equal, but have the same relative ordering. The best example on my mind is a decimal type with a value of 2.0000 and an integer 2. They're not equal, but there's no clear winner for ordering between them. > When comparing objects should be obvoius to use `object` type hint not `mixed` This brings up an interesting talking point. Should an object's `__equals` method only accepts instances of the class (and subclasses)? So object == int would always fail? Or should we allow the method to accept any value and leave it to the user to do an `instanceof`? > That's true, but you want to compare objects not scalar types, right? See above. > I think if you want to push the RFC forward, a really quite strong > case needs to be made for why having it be a language level feature is > so much better (or even at all better) than having it be implemented > in userland. > > > > For example, as it is available in other languages, giving an example > of some code that is much better than the equivalent would be in PHP > could be a good way of showing it is desirable. 1. You can't override the behaviour of `<`, `<=`, `>`, `>=`, `==`, `!=` with a userland implementation. 2. Therefore, you won't be able to affect the internals of array functions like `in_array`, `sort` etc. 3. Having it as a language level feature dictates a standard, which is often hard to establish as a third party. 4. There are some minor but worth mentioning performance advantages in having it be part of the language. Not sure if that is a strong enough case, happy to elaborate some more and provide some code. On Thu, 21 Jun 2018 at 10:59, Dan Ackroyd wrote: > On 21 June 2018 at 10:27, Rudi Theunissen wrote: > > The Comparable RFC (http://wiki.php.net/rfc/comparable) was written in > 2010 > > but was not conclusive. I would like to take > > on some shared responsibility to push this forward and re-open the > > discussion. > > > > Why is this useful, and why should it be added to PHP? > > > I think if you want to push the RFC forward, a really quite strong > case needs to be made for why having it be a language level feature is > so much better (or even at all better) than having it be implemented > in userland. > > For example, as it is available in other languages, giving an example > of some code that is much better than the equivalent would be in PHP > could be a good way of showing it is desirable. > > cheers > Dan > --0000000000001b40a3056f39606f--