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
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: 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

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-2022 The PHP Group
All rights reserved.
Last updated: Sun Jan 23 12:04:05 2022 UTC