Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array Comparison #191

Open
Fleshgrinder opened this issue Feb 3, 2017 · 1 comment
Open

Array Comparison #191

Fleshgrinder opened this issue Feb 3, 2017 · 1 comment

Comments

@Fleshgrinder
Copy link
Contributor

Fleshgrinder commented Feb 3, 2017

In note 5. about array comparisons the following is stated:

If the next key in the left-hand operand does not exist in the right-hand operand, the arrays cannot be compared and FALSE is returned.

This is actually not true in case of the spaceship operator on both PHP and HHVM.

<?php

$lhs = [0 => 0];
$rhs = [1 => 1];

var_dump(
    $lhs < $rhs,
    $lhs <= $rhs,
    $lhs <=> $rhs,
    $lhs >= $rhs,
    $lhs > $rhs
);

/*
bool(false)
bool(false)
int(1)
bool(false)
bool(false)
*/
@bradynpoulsen
Copy link

Good find, that should probably read:
If the next key in the left-hand operand does not exist in the right-hand operand, the arrays cannot be compared and are considered not equal.

The spaceship operator is designed to do a bi-directional comparison. Meaning not only does it report if they are equal or not, it also specifies whether it's greater than or less than. The spaceship operator always returns an integer representing those details (similar to strcmp).

See: http://php.net/manual/en/language.operators.comparison.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants