php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79868 Sorting with array_unique gives unwanted result
Submitted: 2020-07-17 15:22 UTC Modified: 2020-07-19 10:01 UTC
From: dries at vints dot io Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 8.0.0alpha2 OS: macOS Catalina 10.15.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dries at vints dot io
New email:
PHP Version: OS:

 

 [2020-07-17 15:22 UTC] dries at vints dot io
Description:
------------
Sorting with array_unique returns different results than in previous PHP versions. I suspect this is because of https://wiki.php.net/rfc/stable_sorting

If you run the test script from below it'll return the result seeing in https://3v4l.org/9sbAq

Test script:
---------------
var_dump(array_unique([
    'Illuminate\Routing\Middleware\SubstituteBindings',
    'Illuminate\Auth\Middleware\Authorize:edit,post',
], SORT_REGULAR));

Expected result:
----------------
array(2) {
  [0]=>
  string(48) "Illuminate\Routing\Middleware\SubstituteBindings"
  [1]=>
  string(46) "Illuminate\Auth\Middleware\Authorize:edit,post"
}

Actual result:
--------------
array(2) {
  [1]=>
  string(46) "Illuminate\Auth\Middleware\Authorize:edit,post"
  [0]=>
  string(48) "Illuminate\Routing\Middleware\SubstituteBindings"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-18 11:26 UTC] sjon@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: sjon
 [2020-07-18 11:26 UTC] sjon@php.net
can you explain why "Illuminate\Routing" should be sorted before "Illuminate\Auth" ?
 [2020-07-18 16:37 UTC] dries at vints dot io
-Status: Feedback +Status: Assigned
 [2020-07-18 16:37 UTC] dries at vints dot io
@sjon I can't, I don't dispute the new behavior makes more sense. This was a side effect we didn't forsee. I'm reporting this as a change in behavior after Nikita confirmed this wasn't suppose to change: https://twitter.com/nikita_ppv/status/1284143520962486273
 [2020-07-19 09:56 UTC] sjon@php.net
-Status: Assigned +Status: Verified -Assigned To: sjon +Assigned To: nikic
 [2020-07-19 10:01 UTC] dries at vints dot io
Just to be fully clear: we've already worked around this by writing our own sorting function. If you decided that this is indeed the intended behavior then that would be alright with us.
 [2020-07-20 13:17 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6f8d0ba0dd7d9e96ec6b2b75337f701a5ce3d3f0
Log: Fix bug #79868
 [2020-07-20 13:17 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2020-07-23 12:24 UTC] dries at vints dot io
Thanks Nikita!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC