Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8754 invoked from network); 19 Apr 2015 23:50:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2015 23:50:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.42 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.42 mail-pa0-f42.google.com Received: from [209.85.220.42] ([209.85.220.42:36426] helo=mail-pa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/41-34018-64F34355 for ; Sun, 19 Apr 2015 19:50:31 -0400 Received: by pabsx10 with SMTP id sx10so188698454pab.3 for ; Sun, 19 Apr 2015 16:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=QvAhci3QNt8PuGpLhEmZ1ZViM3wA2pt3Ma5YgkQNWJM=; b=Ae0Y1B8jFZBbk4onMT3X0fDusJWP8cKqEBWYZGzOXoBYxKxuU4dkW2FubFDNk7YpjZ e0hqCwOW9OcE2F3cum93oGT66tJbGnkwmK3JhKw+ftqeJiwpReXFrQrOHuUqKDst8HJj 9a5fy++wOMyWDb22c4bJGdqfWGm88E/SeNQz1iJu7PX4sIAIfQmu/9W8ulV4OM8kBwLs kgRVp3F3On0q4FjyzQ53L+L3twR42I/IPq1p04mnrB30yVZKr3j3VyoTdlrCvZaxCzxP emnCC3UbJzsdCbK68PNmLZxZaKbybqU0lnOv00JMRz3M0hRT6eVsd3p5Qw8/Yarrn2CO YTWg== X-Received: by 10.68.226.4 with SMTP id ro4mr23579633pbc.108.1429487427489; Sun, 19 Apr 2015 16:50:27 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id b9sm16305481pas.40.2015.04.19.16.50.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2015 16:50:26 -0700 (PDT) Message-ID: <55343F3E.3010307@gmail.com> Date: Sun, 19 Apr 2015 16:50:22 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Christoph Becker , PHP Internals References: <54E35490.9040709@gmail.com> <5533A275.7050303@gmx.de> <55342724.6020606@gmail.com> <55342C8D.7020509@gmx.de> In-Reply-To: <55342C8D.7020509@gmx.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [RFC] Spaceship operator RFC From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > There is the following example in the RFC: > > // only values are compared > $a = (object) ["a" => "b"]; > $b = (object) ["b" => "b"]; > echo $a <=> $b; // 0 > > But the actual result is currently 1, not 0. Ahh, I see. I think it's the mistake in the RFC. These objects are not equal, so <=> can not return 0. These objects are compared as hashtables (see zend_hash_compare), since $a has key "a" and $b does not, comparison returns 1. Since objects by default are not well-ordered, comparison does not follow the rules of order, i.e. it may happen that both $a > $b and $b > $a. That's how compare_function works and always worked, and <=> is just a call to that function. > When there is no "right" value, why not raising E_NOTICE at least. It I'm not a big fan of throwing too many notices. They are usually not very helpful an din this case it would be not easy to distinguish between intentional and unintentional use. > appears to me that returning 1 (as "undefined") without further notice > is too misleading, as it suggests that $a is greater than $b, but that > is not true: ($a > $b === false). $a > $b being false is an artifact of how ">" works in the engine - $a > $b is essentially ($b < $a). Since in this case both $a > $b and $b > $a, the result of ($b < $a) is false. That's what you get when you compare non-well-ordered things... -- Stas Malyshev smalyshev@gmail.com