Bug #70746 [NEW]: Please document spaceship as returning -1 or 0 or 1
| From: | lbayuk at users dot sourceforge dot net | Date: | Mon, 19 Oct 2015 22:19:59 +0000 |
| Subject: | Bug #70746 [NEW]: Please document spaceship as returning -1 or 0 or 1 | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-12827@lists.php.net to get a copy of this message | ||
From: lbayuk at users dot sourceforge dot net
Operating system:
PHP version: 7.0.0RC5
Package: Documentation problem
Bug Type: Bug
Bug description:Please document spaceship as returning -1 or 0 or 1
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 bug report at https://bugs.php.net/bug.php?id=70746&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70746&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70746&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70746&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70746&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70746&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70746&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70746&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70746&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70746&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70746&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70746&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70746&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70746&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70746&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70746&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70746&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70746&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70746&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70746&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70746&r=mysqlcfg