From: of dot olivier dot favre at gmail dot com
Operating system:
PHP version: 5.4.17
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:array_unique with SORT_REGULAR inconsistently compare 1 and "1"
Description:
------------
The doc claims âSORT_REGULAR - compare items normally (don't change
types)â
Hence (int)1 and (string)"1" should both be considered non duplicates.
Current results with SORT_REGULAR are too unpredictable for this
function/flag to
be useful.
See #47370:
âI think it's better for SORT_REGULAR to compare elements by using ===
instead of
==.â
Request:
Add a SORT_STRICT flag using strict === comparison between elements.
(prevents
from changing SORT_REGULAR behavior).
Tested on:
Debian GNU/Linux 7.1 (wheezy)
$ php --version
PHP 5.4.4-10 (cli) (built: Nov 24 2012 11:21:26)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
Test script:
---------------
var_export(array_unique(array( 1, 2, 2, 3, "1"), SORT_REGULAR)); // "1" is
suppressed!
echo "\n";
var_export(array_unique(array( 1, 2, 2, 3, "1", "c"), SORT_REGULAR)); //
"1" and "c" are kept (as it should be)
echo "\n";
// Weirder, with the same values in an other order
var_export(array_unique(array( 1, 2, 2, 3, "1", "c"), SORT_REGULAR)); //
"1" and "c" are kept (as it should be)
echo "\n";
var_export(array_unique(array( "c", 1, 2, 2, 3, "1"), SORT_REGULAR)); //
"1" is suppressed!
echo "\n";
Expected result:
----------------
array (
0 => 1,
1 => 2,
3 => 3,
4 => '1',
)
array (
0 => 1,
1 => 2,
3 => 3,
4 => '1',
5 => 'c',
)
array (
0 => 1,
1 => 2,
3 => 3,
4 => '1',
5 => 'c',
)
array (
0 => 'c',
1 => 1,
2 => 2,
4 => 3,
5 => '1',
)
Actual result:
--------------
array (
0 => 1,
1 => 2,
3 => 3,
)
array (
0 => 1,
1 => 2,
3 => 3,
4 => '1',
5 => 'c',
)
array (
0 => 1,
1 => 2,
3 => 3,
4 => '1',
5 => 'c',
)
array (
0 => 'c',
1 => 1,
2 => 2,
4 => 3,
)
--
Edit bug report at https://bugs.php.net/bug.php?id=65208&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65208&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65208&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65208&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65208&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65208&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65208&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65208&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65208&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65208&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65208&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65208&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65208&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65208&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65208&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65208&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65208&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65208&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65208&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65208&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65208&r=mysqlcfg