Bug #71334 [Asn->Csd]: Cannot access array keys while uksort()
Edit report at https://bugs.php.net/bug.php?id=71334&edit=1
ID: 71334
Updated by: nikic@php.net
Reported by: alex dot schneider at sevenval dot com
Summary: Cannot access array keys while uksort()
-Status: Assigned
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Linux Mint 17.3
PHP Version: 7.0.2
Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b1e854f7762b2e0648ddc240835cb446ee4d20a7
Log: Fix bug #71334
Previous Comments:
------------------------------------------------------------------------
[2016-03-30 20:38:20] nikic@php.net
Related To: Bug #71926
------------------------------------------------------------------------
[2016-02-22 12:55:25] nikic@php.net
New patch that resolves the ArrayObject issue: https://github.com/nikic/php-src/commit/73e6c257abc9ad5a5aef6b91a2238e941b2045d5
------------------------------------------------------------------------
[2016-01-13 16:15:11] jsgoupil at gmail dot com
I have the same problem, I am able to access the values, but the sorting is not correct.
<?php
function cmp($a, $b)
{
$x = $GLOBALS['x'];
$v1 = $x[$a];
$v2 = $x[$b];
if ($v1 < $v2) {
return -1;
} elseif ($v1 > $v2) {
return 1;
} else {
// Would then sort by key, irrelevant here.
}
}
$x = array(1 => 1, 2 => 3, 3 => 2);
uksort($x, 'cmp');
var_dump($x);
// PHP5
array(3) { [1]=> int(1) [3]=> int(2) [2]=> int(3) }
// PHP7
array(3) { [3]=> int(2) [2]=> int(3) [1]=> int(1) }
Let me know if you want me to open another bug instead.
------------------------------------------------------------------------
[2016-01-13 06:36:55] laruence@php.net
hmm, we could also adjust arHash after swap, but it must not be a simple patch..
thanks
------------------------------------------------------------------------
[2016-01-12 16:36:08] nikic@php.net
It looks like ArrayObject relies on sorting functions not to duplicate the array for the rc=1 case,
so this will need some more work :(
------------------------------------------------------------------------
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
https://bugs.php.net/bug.php?id=71334
--
Edit this bug report at https://bugs.php.net/bug.php?id=71334&edit=1
Thread (7 messages)