Hi!
Stanislav Malyshev wrote:
>
>> A discrepancy between the actual behavior of the spaceship operator and
>> an example given in its RFC has been reported recently (bug #69466[1]).
>
> I'm not sure what the discrepancy is, could you explain?
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.
>> To me it appears that there is a contradiction in the RFC (see my
>> comment on the respective report), which would have to be resolved one
>> way or another.
>
> I don't see the contradiction. The objects in your example are not
> comparable, since $a < $b and $b < $a are both not true, 1 is returned.
> Returning 0 would be wrong of course since these objects are not equal.
> In fact, there's no "right" value in this case as objects are not
> comparable - so the result is undefined. In this case, undefined is 1.
When there is no "right" value, why not raising E_NOTICE at least. It
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).
--
Christoph M. Becker
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php