Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102397 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17576 invoked from network); 24 Jun 2018 18:00:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jun 2018 18:00:13 -0000 Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.52 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.52 mail-lf0-f52.google.com Received: from [209.85.215.52] ([209.85.215.52:46686] helo=mail-lf0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/FB-13077-32CDF2B5 for ; Sun, 24 Jun 2018 14:00:12 -0400 Received: by mail-lf0-f52.google.com with SMTP id v17-v6so5671005lfe.13 for ; Sun, 24 Jun 2018 11:00:02 -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=mT6C4OHIOOD+8sIvlA43sOD208WuLrZg9FEk5VmKJDc=; b=AWwUb9YxxmbLKpLz3G1Ag1n3pepcK8wHumYNMWUV16bCPd3vfmdFouPEPTlvq+34p4 IzTJQaovOtIQmW1alpVkFhe+0Mhcxjzjv2PEBXoadypGCEKP3GA3xwOtmAm3XeUZn6FS vMVlH7CQaau/0YaghbAQMXC8t/C+NKChq46LBTU5eUnE/+tvYdOnoMwshc2qrbCKFwJo jAT5IOw3z7Gh327tjH9V0Rf1nZ6m/k75PkvTeqnpzqDvn1XFuNHK3HF1HOyc2mLOG3VS FzjuXmfI0W923wPvuL9FnOy0sAJIMr1Peo/QweeOWb4oNF7n1jKvSf+r/QkLZ+5L+dgy fO6Q== X-Gm-Message-State: APt69E1vQtQyNvngbGiE3/Tk/n5i/dEoHRQSJ3syKMkUNTZGbTSJYGU0 car1Zl0TPBH7ZX+Qnt9oP/bxGisMRKIaWypW8uA= X-Google-Smtp-Source: ADUXVKKyA2zftS0xMkQ3WPQ/AjsZ/xzNAf0E3yy1rgZ/vaLPIuX+YoiJuzKD1F+lDTQk3kuHWQeqJVXhFLomZB50Wjs= X-Received: by 2002:a19:ca5c:: with SMTP id h28-v6mr3762021lfj.142.1529863199381; Sun, 24 Jun 2018 10:59:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 24 Jun 2018 11:59:47 -0600 Message-ID: To: rtheunissen@php.net Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Equality and relative ordering of objects From: levim@php.net (Levi Morrison) On Sun, Jun 24, 2018 at 11:28 AM Rudi Theunissen wrote: > > The idea behind the nullable return is to allow for partial support, where you might want to check for > equality but ignore ordering. You can't return nothing or NULL if we normalise to -1,0,1 because NULL > would be 0 and therefore indicate that the values are equal. > > We could require that the user always returns an integer, and suggest -1 to be returned when there's no > clear definition for ordering. The null return was to avoid returning that -1 when ordering isn't defined. > > ``` > class Equatable { > public function __compareTo($other) { > if ($other instanceof self && $this->prop === $other->prop) { > return 0; > } > > // No logical ordering exists, so we're not concerned? > } > } > ``` > > > As it stands, we have a few options here: > > 1. Allow anything to be returned and normalise to -1, 0 and 1. > 2. Require an integer, error when anything else is returned, suggest -1 as a comparison-not-defined convention. > 3. Use NULL (or void return) as an indication that the comparison couldn't be made, fall through to compare_objects. > 4. Use NULL (or void return) as an indication that the comparison couldn't be made, internal error. In these schemes I am not understanding how to specify that something is not equal, not ordered, and should not fall back to something else. Consider things like UUIDs and other identifiers where equality is desired and ordering does not make sense. Other languages (most? all?) separate equality and ordering for this reason; I think we ought to do the same.