ID: 12936
Updated by: andrei
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Closed
Bug Type: Arrays related
Operating System: linux
PHP Version: 4.0.4
New Comment:

It's a side-effect of the implementation. It could be fixed if I forced all arguments 
to be passed by reference, but that means that you can't specify SORT_* constants 
directly as arguments..

Previous Comments:
------------------------------------------------------------------------

[2001-08-23 22:17:34] [EMAIL PROTECTED]

When called inside a function array_multisort changes the global variables instead of 
the local copy the function should be working with.

<?php

$sortKeys = array(3, 2, 4, 1, 5);
$a = array(111 => '111', 222 => '222', 333 => '333', 444 => '444',
           555 => '555');

echo "initial arrays:<br>";
echo "sortKeys: "; var_dump($sortKeys); echo "<br>";
echo "a: "; var_dump($a); echo "<br>";

echo "<br>";

msortWithRef($sortKeys, $a);

echo "after msortWithRef:<br>";
echo "sortKeys: "; var_dump($sortKeys); echo "<br>";  
echo "a: "; var_dump($a); echo "<br>";  

echo "<br>";

msortWithoutRef($sortKeys, $a);    

echo "after msortWithoutRef:<br>";
echo "sortKeys: "; var_dump($sortKeys); echo "<br>";
echo "a: "; var_dump($a); echo "<br>";

function msortWithoutRef($array1, $array2)
{
    array_multisort($array1, $array2);
}

function msortWithRef($array1, $array2)
{
    array_multisort(&$array1, &$array2);
}

?>

output:

initial arrays:
sortKeys: array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(4) [3]=> int(1) [4]=> int(5) 
} 
a: array(5) { [111]=> string(3) "111" [222]=> string(3) "222" [333]=> string(3) "333" 
[444]=> string(3) "444" [555]=> string(3) "555" } 

after msortWithRef:
sortKeys: array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(4) [3]=> int(1) [4]=> int(5) 
} 
a: array(5) { [111]=> string(3) "111" [222]=> string(3) "222" [333]=> string(3) "333" 
[444]=> string(3) "444" [555]=> string(3) "555" } 

after msortWithoutRef:
sortKeys: array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) 
} 
a: array(5) { [0]=> string(3) "444" [1]=> string(3) "222" [2]=> string(3) "111" [3]=> 
string(3) "333" [4]=> string(3) "555" } 

------------------------------------------------------------------------



Edit this bug report at http://bugs.php.net/?id=12936&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to