Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102401 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27477 invoked from network); 24 Jun 2018 20:31:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jun 2018 20:31:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=rudolf.theunissen@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rtheunissen@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: rudolf.theunissen@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-ua0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:35097] helo=mail-ua0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/8D-13077-7AFFF2B5 for ; Sun, 24 Jun 2018 16:31:36 -0400 Received: by mail-ua0-f177.google.com with SMTP id s13-v6so7357158uad.2 for ; Sun, 24 Jun 2018 13:31:35 -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=ceZaqx7LRIhbBA+kQYT0K/kBmc/jEjWS1hvv4YPWQkE=; b=IwfayRy0Z2VKwKis8+TRiZtpaJAy5DB7g5XLde3PgcuoMKS01r1e3vJB9B3by4HGSp rGp9nLoXciw3orFhwfjAXu7X6/M9UAMAsVPCwtcfern0v28LVnP9icTkLJDAy7+XJeEW tBSPqftUm+lrOtNjJ1EPbt/nTh4j/oNDwzo2+60uLZSPXlRfkixdLoYwPYVVNmhRWNwf mQM1+ph2yBwkHbd37lnk3IahvEoZ5NOR8+jaHddKUT/fCn89sllete/4YyyeJ9Jl+U8c 2RABX1WjXNICgHmAge7PafKPbkED/G2fN7cT9Lh8TQGM2CNbs042gvjjTGo8IlBM0Z2E W2tA== X-Gm-Message-State: APt69E0h/NzBHTio/IQ16imafdiiPex3ysGoLxJSwazBxeVtIhl+Hf4F ol2TkQRczmnUAdyN597R/OPE22EH X-Google-Smtp-Source: AAOMgpd5THvMRA16RtMEh5NDg9kCBqq/SHvrH0AmmMb8PbTMRVcU6evw7pftvTJat478VFu1l7fatg== X-Received: by 2002:a9f:3fc4:: with SMTP id m4-v6mr4474965uaj.38.1529872292830; Sun, 24 Jun 2018 13:31:32 -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 a7-v6sm4590453uai.11.2018.06.24.13.31.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Jun 2018 13:31:32 -0700 (PDT) Received: by mail-ua0-f177.google.com with SMTP id m21-v6so7367457uan.0 for ; Sun, 24 Jun 2018 13:31:32 -0700 (PDT) X-Received: by 2002:ab0:7207:: with SMTP id u7-v6mr5329222uao.99.1529872291976; Sun, 24 Jun 2018 13:31:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 24 Jun 2018 16:31:20 -0400 X-Gmail-Original-Message-ID: Message-ID: To: levim@php.net Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000083e186056f692655" Subject: Re: [PHP-DEV] Equality and relative ordering of objects From: rtheunissen@php.net (Rudi Theunissen) --00000000000083e186056f692655 Content-Type: text/plain; charset="UTF-8" > > Other languages (most? all?) separate equality and ordering for this > reason. Java doesn't really separate them. Their `==` always checks object reference so is like PHP's ===. But they do have the .equals() method on all objects (our ==) and the collections use that for equality. 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. For something to be not equal, you return anything but 0. If something is not ordered, you return -1 (LHS wins). If you don't want something to fall back to any default behaviour, just return an integer and not NULL. The realistic case, in my opinion, is that there will always be *some* property to order by, whether it's the object's numeric value, a string that can be alphabetical, or a time based element. We can argue that if the object doesn't have a defined, logical ordering, then it also wouldn't make sense to order a collection of them in the first place. So with that in mind, maybe it's okay to take "NULL falls back to default behaviour" idea out, and do a normalisation on whatever the user returns. If it's NULL, then that'll be 0, and the value will be equal. The only thing I don't like about that is that the user didn't specify "equal" with a 0, they returned the absence of a direction, and we should therefore either throw an exception internally, or fall back to the current comparison behaviour (comparing properties). The NULL return is a special case for me. Anything else is *some* value that can be normalised ($v ? ($v < 0 ? -1 : 1) : 0). Therefore, I believe it comes down to a simply question: how do we handle the case where __compareTo returns NULL? --00000000000083e186056f692655--