Bug #70746 [Opn->Ver]: Please document spaceship as returning -1 or 0 or 1
| From: | jhdxr@php.net | Date: | Wed, 21 Oct 2015 15:26:17 +0000 |
| Subject: | Bug #70746 [Opn->Ver]: Please document spaceship as returning -1 or 0 or 1 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12830@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70746&edit=1
ID: 70746
Updated by: jhdxr@php.net
Reported by: lbayuk at users dot sourceforge dot net
Summary: Please document spaceship as returning -1 or 0 or 1
-Status: Open
+Status: Verified
Type: Bug
Package: Documentation problem
PHP Version: 7.0.0RC5
-Assigned To:
+Assigned To: jhdxr
Block user comment: N
Private report: N
New Comment:
I have created a patch via edit.php.net
waiting for review.
Previous Comments:
------------------------------------------------------------------------
[2015-10-19 23:16:25] lbayuk at users dot sourceforge dot net
Typos:
"it always returns -1, 0, or -1. As coded it seems to return -1, 0, or -1"
should of course be:
"it always returns -1, 0, or 1. As coded it seems to return -1, 0, or 1"
Sorry about that.
------------------------------------------------------------------------
[2015-10-19 22:19:56] lbayuk at users dot sourceforge dot net
Description:
------------
Currently the PHP manual says the PHP7 'spaceship' comparison operator <=> returns
"An integer less than, equal to, or greater than zero when $a is respectively less than, equal
to, or greater than $b".
In the original RFC for this feature https://wiki.php.net/rfc/combined-comparison-operator
the behavior was more specific: It returns -1, 0, or 1 depending on the result of the comparison.
It seems to me that the actual implementation matches the RFC: it always returns -1, 0, or -1. As
coded it seems to return -1, 0, or -1 at least for all simple types such as numbers and strings. I
would like to see it documented per the RFC, returning -1, 0, or 1, so we could rely on that
behavior.
The orginal behavior was more useful, as it allowed for coding things like this:
$table[($a <=> $b) + 1]
to index a $table with 3 entries depending on the outcome of the 3-way comparison.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70746&edit=1