ID: 47370
Updated by: [email protected]
Reported By: for-bugs at hnw dot jp
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: any
PHP Version: 5.2.9RC1
Previous Comments:
------------------------------------------------------------------------
[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/
------------------------------------------------------------------------
[2009-02-12 18:12:35] [email protected]
Verified with 5.2, 5.3, HEAD.
------------------------------------------------------------------------
[2009-02-12 16:25:59] for-bugs at hnw dot jp
Sorry, reproduce code was incorrect. Correct code is below:
<?php
var_dump(array_unique(array(0,"","0")));
var_dump(array_unique(array("","0",0)));
------------------------------------------------------------------------
[2009-02-12 16:22:38] for-bugs at hnw dot jp
Description:
------------
In PHP5.2.9RC1, array_unique() returns different result because of
element ordering in array. Reproduce code shows this difference.
It is because SORT_REGULAR never cast array elements and compares them
with ==. I think it's better for SORT_REGULAR to compare elements by
using === instead of ==.
PHP 5.2.9RC1's array_unique() also has backward compatibility ploblem.
Considering backward compatibility, default sort_flag should be
SORT_STRING.
Reproduce code:
---------------
<?php
var_dump(arary_unique(array(0,"","0"))));
var_dump(arary_unique(array("","0",0))));
Expected result:
----------------
I don't know, but 2 results should be same.
Actual result:
--------------
array(1) {
[0]=>
int(0)
}
array(2) {
[0]=>
string(0) ""
[1]=>
string(1) "0"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47370&edit=1