php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69891 Unexpected array comparison result
Submitted: 2015-06-20 13:58 UTC Modified: 2015-06-20 14:00 UTC
From: colinodell at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Arrays related
PHP Version: 7.0Git-2015-06-20 (Git) OS: Ubuntu 14.04.1 LTS 3.13.0-34-gen
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 11 = ?
Subscribe to this entry?

 
 [2015-06-20 13:58 UTC] colinodell at gmail dot com
Description:
------------
Using the comparison (spaceship) operator on arrays with different lengths produces unexpected results.  It seems to be returning the difference in length instead of restricting the output to -1, 0, or 1.

I am using Zend's Debian nightly build: PHP 7.0.0-dev (cli) (built: Jun 19 2015 19:09:04)

Test script:
---------------
// Here's a direct example from the RFC, which says this
// should evaluate to 1. However, I get 3 instead:
echo [1, 2, 3] <=> [];

// Here are some other examples:
echo [1, 2, 3, 4, 5] <=> [];  // 5
echo [] <=> [1, 2, 3, 4, 5];  // -5
echo [1, 2, 3, 4, 5] <=> [1]; // 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-20 14:00 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2015-06-20 15:36 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e8217a2727b20997e6f39d59c44a20cc61d7e6c7
Log: Fix bug #69891
 [2015-06-20 15:36 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e8217a2727b20997e6f39d59c44a20cc61d7e6c7
Log: Fix bug #69891
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e8217a2727b20997e6f39d59c44a20cc61d7e6c7
Log: Fix bug #69891
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 20:01:32 2024 UTC