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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: colinodell at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Apr 19 19:01:28 2024 UTC