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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ermolaev-nv at ro dot ru
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 11:01:35 2025 UTC