Bug #70746 [Opn]: Please document spaceship as returning -1 or 0 or 1

From: Date: Mon, 19 Oct 2015 23:16:26 +0000
Subject: Bug #70746 [Opn]: 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-12828@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 User updated by: lbayuk at users dot sourceforge dot net Reported by: lbayuk at users dot sourceforge dot net Summary: Please document spaceship as returning -1 or 0 or 1 Status: Open Type: Bug Package: Documentation problem PHP Version: 7.0.0RC5 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#12828) next »