php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75513 uksort not working correctly in php 5.6.32
Submitted: 2017-11-13 05:17 UTC Modified: 2017-11-13 06:33 UTC
From: daniel at ciokix dot ro Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.32 OS: Ubuntu 14.04
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: daniel at ciokix dot ro
New email:
PHP Version: OS:

 

 [2017-11-13 05:17 UTC] daniel at ciokix dot ro
Description:
------------
Although this issue is not reproducible in php7 or later, it occurs in php5.6.32 and it would be great if it could be fixed in the next php5.6 release.

Test script:
---------------
The differences regarding uksort response for php5.6 and php7 can be seen on 3v4l: https://3v4l.org/Lfq4C


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-13 06:33 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-11-13 06:33 UTC] requinix@php.net
Your comparison function is inconsistent: for example, it will claim that l=a (neither value depends on the other) and that t=l (same) yet it would claim that a<t. PHP 5.6 does not attempt that comparison because (a) that was sheer luck based on the ordering of the original array, but more importantly (b) it could/should logically infer that a=t based on the previous results.

PHP 7's sorting behavior changed and the problem is no longer apparent for that given ordering; I tried shuffling randomly a couple times but didn't get any incorrect results, however it's quite possible there is at least one original array ordering that will expose the same flaw.

PHP's quicksort is not really the right tool for this job. A topological sort is the most appropriate answer in theory but a simple insertion sort may be sufficient.

Regardless, 5.6 has reached end of life and is only receiving security-related fixes now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC