ID: 47370
User updated by: for-bugs at hnw dot jp
Reported By: for-bugs at hnw dot jp
Status: Assigned
Bug Type: Arrays related
Operating System: *
-PHP Version: 5.2.9RC1
+PHP Version: 5.2.9
Assigned To: andrei
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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] [email protected]
This was not discussed, and thus no bogus thing.
------------------------------------------------------------------------
[2009-02-13 22:27:35] [email protected]
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.
------------------------------------------------------------------------
[2009-02-13 01:53:09] for-bugs at hnw dot jp
Thank you so much. The snapshot returns same result to PHP 5.2.8 with
reproduce code. Such as:
array(2) {
[0]=>
int(0)
[1]=>
string(0) ""
}
array(2) {
[0]=>
string(0) ""
[1]=>
string(1) "0"
}
------------------------------------------------------------------------
[2009-02-12 18:58:34] [email protected]
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
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