Bug #66544 [NEW]: uasort works incorrent in some cases
| From: | korovkin dot kirill at gmail dot com | Date: | Wed, 22 Jan 2014 14:11:34 +0000 |
| Subject: | Bug #66544 [NEW]: uasort works incorrent in some cases | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183951@lists.php.net to get a copy of this message | ||
From: korovkin dot kirill at gmail dot com
Operating system: Linux 2.6.32-042stab07
PHP version: 5.4.24
Package: *General Issues
Bug Type: Bug
Bug description:uasort works incorrent in some cases
Description:
------------
You can see all information in the test script.
Test script:
---------------
$inputArray = array(
'shipping' => array(
'after' => array(),
'before' => array(),
'_code' => 'shipping'
),
'freeshipping' => array(
'after' => array(),
'before' => array(),
'_code' => 'freeshipping'
),
'discount' => array(
'after' => array('shipping', 'tax_shipping'),
'before' => array(),
'_code' => 'discount'
),
'tax_shipping' => array(
'after' => array('shipping'),
'before' => array('discount'),
'_code' => 'tax_shipping'
)
);
function compare ($a, $b) {
$aCode = $a['_code'];
$bCode = $b['_code'];
if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) {
$res = -1;
} elseif (in_array($bCode, $a['after']) || in_array($aCode,
$b['before'])) {
$res = 1;
} else {
$res = 0;
}
return $res;
}
uasort($inputArray, 'compare');
var_dump(array_keys($inputArray));
Expected result:
----------------
array (size=4)
0 => string 'shipping' (length=8)
1 => string 'tax_shipping' (length=12)
2 => string 'discount' (length=8)
3 => string 'freeshipping' (length=12)
Or another position for 'freeshipping'. But 'shipping' must be before
'tax_shipping' and 'discount' must be after 'tax_shipping'.
Actual result:
--------------
array (size=4)
0 => string 'tax_shipping' (length=12)
1 => string 'discount' (length=8)
2 => string 'freeshipping' (length=12)
3 => string 'shipping' (length=8)
--
Edit bug report at https://bugs.php.net/bug.php?id=66544&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66544&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66544&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66544&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66544&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66544&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66544&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66544&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66544&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66544&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66544&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66544&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66544&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66544&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66544&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66544&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66544&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66544&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66544&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66544&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66544&r=mysqlcfg