Bug #69466 [Opn->Ver]: Spaceship operator rfc discrepancy

From: Date: Thu, 16 Apr 2015 11:17:51 +0000
Subject: Bug #69466 [Opn->Ver]: Spaceship operator rfc discrepancy
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192130@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69466&edit=1

 ID:                 69466
 Updated by:         cmb@php.net
 Reported by:        ppasindud at gmail dot com
 Summary:            Spaceship operator rfc discrepancy
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            *General Issues
 Operating System:   not need
 PHP Version:        master-Git-2015-04-16 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

It seems the RFC[1] contradicts itself:

| It is implemented by using the result of the existing internal
| compare_function that underlies the other comparison operators.

but:

| // only values are compared
| $a = (object) ["a" => "b"]; 
| $b = (object) ["b" => "b"]; 
| echo $a <=> $b; // 0

However:

    var_dump($a < $b); // => bool(false)
    var_dump($b < $a); // => bool(false)
    
And currently:

    echo $a <=> $b; // => 1
    echo $b <=> $a; // => 1
    
Apparently, there is a problem with comparing unordered values with
the spaceship operator.
    
[1] <https://wiki.php.net/rfc/combined-comparison-operator>


Previous Comments:
------------------------------------------------------------------------
[2015-04-16 08:32:27] ppasindud at gmail dot com

Description:
------------
http://3v4l.org/g5mCe

Test script:
---------------
<?php


$a = (object) ["a" => "c"]; 
$b = (object) ["a" => "b"]; 
echo $a <=> $b; // 1

// only values are compared
$a = (object) ["a" => "b"]; 
$b = (object) ["b" => "b"]; 
echo $a <=> $b; // 0


Expected result:
----------------
10

Actual result:
--------------
11


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69466&edit=1


Thread (7 messages)

« previous php.bugs (#192130) next »