Bug #81692 [Ver]: array_unique bug
| From: | requinix@php.net | Date: | Fri, 03 Dec 2021 15:13:58 +0000 |
| Subject: | Bug #81692 [Ver]: array_unique bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-238139@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81692&edit=1
ID: 81692
Updated by: requinix@php.net
Reported by: stanislav dot eismont at gmail dot com
Summary: array_unique bug
Status: Verified
Type: Bug
Package: Arrays related
Operating System: ubuntu 20.04
PHP Version: 7.4.26
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Isn't this just a result of inconsistent comparisons during sorting? The sorted arrays
don't place the two reds next to each other with SORT_REGULAR; they do if you use SORT_STRING,
which also produces the expected unique array.
https://3v4l.org/JTQMr
https://3v4l.org/gPaPn
Previous Comments:
------------------------------------------------------------------------
[2021-12-03 12:25:04] cmb@php.net
Indeed, broken as of PHP 7.0.0: <https://3v4l.org/PXQZe>.
------------------------------------------------------------------------
[2021-12-03 11:30:02] stanislav dot eismont at gmail dot com
Description:
------------
array_unique returns incorrect result with SORT_REGULAR flag.
Test script:
---------------
<?php
$array = ["red", "color" => "red", 78, 78, 12, "12",
false, null, false, 0, true, 1, 0, null, 2.12, "2.12", 8, "-s"];
var_dump(array_unique($array, SORT_REGULAR));
Expected result:
----------------
Expected one "red" value printed:
array(11) {
[0]=>
string(3) "red"
// ...
}
Actual result:
--------------
Actually "red" printed twice:
array(11) {
[0]=>
string(3) "red"
["color"]=>
string(3) "red"
// ...
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81692&edit=1