Doc #70746 [Ver->Csd]: Please document spaceship as returning -1 or 0 or 1
| From: | bwoebi@php.net | Date: | Thu, 22 Oct 2015 01:43:45 +0000 |
| Subject: | Doc #70746 [Ver->Csd]: 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-12832@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: bwoebi@php.net
Reported by: lbayuk at users dot sourceforge dot net
Summary: Please document spaceship as returning -1 or 0 or 1
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: 7.0.0RC5
Assigned To: jhdxr
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2015-10-22 01:41:31] bwoebi@php.net
Automatic comment from SVN on behalf of bwoebi
Revision: http://svn.php.net/viewvc/?view=revision&revision=338015
Log: Fix bug #70746 (Please document spaceship as returning -1 or 0 or 1)
------------------------------------------------------------------------
[2015-10-21 15:26:17] jhdxr@php.net
I have created a patch via edit.php.net
waiting for review.
------------------------------------------------------------------------
[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