php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70770 Natsort: different results for PHP5 and PHP7
Submitted: 2015-10-22 13:41 UTC Modified: 2015-10-23 03:21 UTC
From: tronsha at gmx dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0Git-2015-10-22 (Git) OS:
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: tronsha at gmx dot de
New email:
PHP Version: OS:

 

 [2015-10-22 13:41 UTC] tronsha at gmx dot de
Description:
------------
---
From manual page: http://www.php.net/function.natsort
---

I get different results for PHP5 and PHP7

PHP 5

Array
(
    [5] => 0
    [1] => 8
    [3] => 009
    [0] => 09
    [2] => 10
    [4] => 011
)

PHP 7 (dev)

Array
(
    [5] => 0
    [1] => 8
    [0] => 09
    [3] => 009
    [2] => 10
    [4] => 011
)

Test script:
---------------
<?php
$zeros = array('09', '8', '10', '009', '011', '0');
natsort($zeros);
print_r($zeros);


Expected result:
----------------
Array
(
    [5] => 0
    [1] => 8
    [3] => 009
    [0] => 09
    [2] => 10
    [4] => 011
)

Actual result:
--------------
Array
(
    [5] => 0
    [1] => 8
    [0] => 09
    [3] => 009
    [2] => 10
    [4] => 011
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-22 16:01 UTC] rasmus@php.net
-Status: Open +Status: Analyzed
 [2015-10-22 16:01 UTC] rasmus@php.net
This is likely because 09 and 009 are actually equivalent in a natural sort and the backend sorting algorithm has changed and the order of equivalent elements don't always match the old algorithm. Both outputs are correct there as far as I am concerned.
 [2015-10-23 03:21 UTC] laruence@php.net
-Status: Analyzed +Status: Not a bug
 [2015-10-23 03:21 UTC] laruence@php.net
yes, we are using stable sorting algo in some cases now, so this is a expected behavior.
 [2015-10-23 06:50 UTC] tronsha at gmx dot de
Ok, not a bug. 
But perhaps it should be noted in the Documentation. 
After all, the result of the function changes.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 04:01:31 2024 UTC