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
 [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

Pull Requests

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: Thu Nov 21 15:01:30 2024 UTC