php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81024 The uasort / uksort function does not work correctly
Submitted: 2021-05-09 22:05 UTC Modified: 2021-05-09 22:07 UTC
From: ermolaev-nv at ro dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 8.0.6 OS: Docker php:8.0.6-cli-alpine3.12
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
31 + 15 = ?
Subscribe to this entry?

 
 [2021-05-09 22:05 UTC] ermolaev-nv at ro dot ru
Description:
------------
The uasort / uksort function does not work correctly

Test script:
---------------
<?php
$ar = [
    [393, 464],
    [-59, 180],
    [-342, 402],
    [-90, 135],
    [-302, 207],
];
uasort($ar, static fn($a, $b) : int => $a[0] > $b[0]);
var_dump($ar);



Expected result:
----------------
array(5) {
  [2]=>
  array(2) {
    [0]=>
    int(-342)
    [1]=>
    int(402)
  }
  [4]=>
  array(2) {
    [0]=>
    int(-302)
    [1]=>
    int(207)
  }
  [3]=>
  array(2) {
    [0]=>
    int(-90)
    [1]=>
    int(135)
  }
  [1]=>
  array(2) {
    [0]=>
    int(-59)
    [1]=>
    int(180)
  }
  [0]=>
  array(2) {
    [0]=>
    int(393)
    [1]=>
    int(464)
  }
}

Actual result:
--------------
array(5) {
  [1]=>
  array(2) {
    [0]=>
    int(-59)
    [1]=>
    int(180)
  }
  [2]=>
  array(2) {
    [0]=>
    int(-342)
    [1]=>
    int(402)
  }
  [4]=>
  array(2) {
    [0]=>
    int(-302)
    [1]=>
    int(207)
  }
  [3]=>
  array(2) {
    [0]=>
    int(-90)
    [1]=>
    int(135)
  }
  [0]=>
  array(2) {
    [0]=>
    int(393)
    [1]=>
    int(464)
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-09 22:07 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Arrays related
 [2021-05-09 22:07 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The callback function must return an integer, not a boolean.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 08 17:01:34 2024 UTC