|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-04-16 08:32 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 31 23:00:01 2025 UTC |
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>