#47370 [Asn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
| From: | jani@php.net | Date: | Thu, 30 Apr 2009 08:26:30 +0000 |
| Subject: | #47370 [Asn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2179@lists.php.net to get a copy of this message | ||
ID: 47370
Updated by: jani@php.net
Reported By: for-bugs at hnw dot jp
Status: Assigned
Bug Type: Documentation problem
Operating System: *
PHP Version: 5.2.9
Assigned To: andrei
New Comment:
See also bug #48115 (yes, WTF?!)
Previous Comments:
------------------------------------------------------------------------
[2009-03-01 07:03:12] moriyoshi@php.net
Andrei, you must add a note about the behavioral change.
------------------------------------------------------------------------
[2009-03-01 00:51:32] for-bugs at hnw dot jp
Hi, Andrei. Here's another terrible example.
<?php
$a=array("10","1az", "1e1");
var_dump(array_unique($a));
$b=array("1e1","10", "1az");
var_dump(array_unique($b));
The result is:
array(3) {
[0]=>
string(2) "10"
[1]=>
string(3) "1az"
[2]=>
string(3) "1e1"
}
array(2) {
[0]=>
string(3) "1e1"
[2]=>
string(3) "1az"
}
The array $a and $b have same 3 elements with different ordering.
Although, two array_unique() returns different result.
First array_unique() returns 3 elements in spite of the fact that "10"
equals "1e1" with ==.
In fact, the two arrays are both sorted about SORT_REGULAR. Because
"10" < "1az" , "1az" < "1e1" and
"1e1"=="10". Sorting with SORT_REGULAR
is not stable, and unique element is not always in neighbor.
This behavior is not obvious for almost all PHP programmer. You should
explain the detail of your function in reference manual.
------------------------------------------------------------------------
[2009-02-14 08:28:18] for-bugs at hnw dot jp
OK, you think comparing elements as string is harmful, doesn't you?
Then, how about array_diff() or array_intersect()? They compare array
elements with string representation. Isn't it harmful?
------------------------------------------------------------------------
[2009-02-14 08:22:26] moriyoshi@php.net
This was not discussed, and thus no bogus thing.
------------------------------------------------------------------------
[2009-02-13 22:27:35] andrei@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 slight BC breakage is negligible compared to the benefits of
getting it to work properly.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/47370
--
Edit this bug report at http://bugs.php.net/?id=47370&edit=1