Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102374 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91019 invoked from network); 22 Jun 2018 21:03:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jun 2018 21:03:26 -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:39254] helo=mail-ua0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/E0-32156-A146D2B5 for ; Fri, 22 Jun 2018 17:03:23 -0400 Received: by mail-ua0-f170.google.com with SMTP id n4-v6so5123934uad.6 for ; Fri, 22 Jun 2018 14:03:22 -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; bh=+1yjQSJdwmrPcaE+nvlt7z/TcsEwchelT+grhCA8gHQ=; b=X5o4vsWXqTNoCOB/zy0TB/5u3Y3BRgNBY68nvcfB5RzRtuOX9C3Fs+T+Lpuuie1W2Y CzKr27pdSkrknmWBeN/OAoCZBFCjt1nEmgowjwDlyTNmAJKnDz3GymWtvQIDosGT1JXN LSiloSgn8AqKkjPUyAKhBOHPwq92dis27b0MUoVT/i//TS5T4WVmdtmEcl6d2xpS0owH AD8VeEM20cGwf75OBI6qbV88NSws9Q6dAoJxJ+N8AscCDNQdHsjdEckH3PGlkdQDSRvT cgzrmDrxsGvKVWuo4ERwufFKwOwo9K46jnaZaf6t34rFfHyfn944+VZh2PpSDlfr3yFs Uccw== X-Gm-Message-State: APt69E28DAJHUch61lXfTHxp66kBrZ39nAgPyB+JIUHrZS1ep/nS4MCd KWnJwkjSV5anU7AC3jSQrZ9wOXCm X-Google-Smtp-Source: ADUXVKJbSfnLSTz9R8k+owqZPu1ZVvvyd+Po4RTcUX+ULrheRJ3qKpq3G6JqfQJTgxvLwiYVnQ+Ndg== X-Received: by 2002:ab0:107:: with SMTP id 7-v6mr2134249uak.138.1529701399902; Fri, 22 Jun 2018 14:03:19 -0700 (PDT) Received: from mail-ua0-f177.google.com (mail-ua0-f177.google.com. [209.85.217.177]) by smtp.gmail.com with ESMTPSA id d69-v6sm2042034vkd.16.2018.06.22.14.03.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 14:03:19 -0700 (PDT) Received: by mail-ua0-f177.google.com with SMTP id d7-v6so5119202uam.13 for ; Fri, 22 Jun 2018 14:03:19 -0700 (PDT) X-Received: by 2002:a9f:2e07:: with SMTP id t7-v6mr2089035uaj.54.1529701399027; Fri, 22 Jun 2018 14:03:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 22 Jun 2018 17:03:07 -0400 X-Gmail-Original-Message-ID: Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000008065bf056f415ca3" Subject: Re: [PHP-DEV] Equality and relative ordering of objects From: rtheunissen@php.net (Rudi Theunissen) --0000000000008065bf056f415ca3 Content-Type: text/plain; charset="UTF-8" On further investigation, I'm not sure if we need both `__equals` and `__compareTo`, even with all the talk about contexts and the fact that an object can be tested for equality and not necessarily ordering as well. If we take out the `__equals` method and only include `__compareTo`, we can allow the user to return NULL to indicate that the object doesn't support the comparison that is being done. So the return values of `__compareTo` then becomes: ``` 1: Greater than -1: Less than 0: Equal to, == NULL: Unsupported, fall back to default behaviour. ``` In the case of an object returning NULL, we can fall back to the default behaviour, which is equivalent to the `compare` handler returning FAILURE, which then falls through to the `compare_objects` handler. I think this will be less confusing and much easier to implement. It's interesting to note that Java's `Comparable` interface considers a 0-return to indicate equality, where a `==` would compare references in the same way PHP's `===` would. So in dropping the `__equals` method, we're slightly more aligned with Java, even though that's not exactly the goal here. :p On Fri, 22 Jun 2018 at 13:55, Rudi Theunissen wrote: > What's the best place to override == internally? `do_operation` or a new > object handler? > I'd like to separate equality from compare_function.. or should we ignore > `__equals ` > and assume that the values are equal if `__compareTo` returns 0? > > Here's some context: I'm modifying `is_equal_function` to check for an > `__equals` > implementation if the value is an object, which I think should work, but > it's not clear how > an internal object (like the ds structures, for example) should override > ==. > > `do_operation` seems like a good choice for this, but I wanted to check > with you all first. > > > > On Fri, 22 Jun 2018 at 13:06, Rudi Theunissen wrote: > >> > Yes, that's the type of thing that I think needs to be included as >> > part of the RFC. >> > >> > Including a list of all the (or at least the important) functions that >> > would be affected by this RFC should be made both for clarity and so >> > that people can think through any edge cases. >> >> >> Absolutely. I was hoping to gather some thoughts and opinions first while >> I >> work on the implementation before I submit an official RFC. I'll make >> sure to >> include what you've mentioned, I completely agree. >> >> On Fri, 22 Jun 2018 at 11:14, Dan Ackroyd wrote: >> >>> On 22 June 2018 at 12:31, Rudi Theunissen wrote: >>> >>> > >>> >> 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. >>> >>> > >>> > >>> > 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. >>> >>> >>> Yes, that's the type of thing that I think needs to be included as >>> part of the RFC. >>> >>> Including a list of all the (or at least the important) functions that >>> would be affected by this RFC should be made both for clarity and so >>> that people can think through any edge cases. >>> >>> cheers >>> Dan >>> >> --0000000000008065bf056f415ca3--