#47370 [Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
From: for-bugs at hnw dot jp Date: Thu, 12 Feb 2009 16:26:00 +0000 Subject: #47370 [Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing References: 1 Groups: php.bugs Request: Send a blank email to php-bugs+get-133768@lists.php.net to get a copy of this message
ID: 47370
User updated by: for-bugs at hnw dot jp
Reported By: for-bugs at hnw dot jp
Status: Open
Bug Type: Arrays related
Operating System: any
PHP Version: 5.2.9RC1
New Comment:
Sorry, reproduce code was incorrect. Correct code is below:
<?php
var_dump(array_unique(array(0,"","0")));
var_dump(array_unique(array("","0",0)));
Previous Comments:
------------------------------------------------------------------------
[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
Thread (12 messages)
- #47370 [Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Opn->Ver]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Ver->Fbk]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Fbk->Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Opn->Csd]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Csd->Bgs]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Bgs->Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Opn->Bgs]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Bgs->Opn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Opn->Asn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
- #47370 [Asn]: array_unique has backward compatibility problem, and SORT_REGULAR is confusing
| « previous | php.bugs (#133768) | next » |
|---|