mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00

Always duplicate the array before doing a sort with user-defined comparison function, to avoid access to the intermediate inconsistent state. I've also dropped the "array modification" warning, as protection against modifications is no longer relevant if we're always working on a copy anyway. This also required some changes to how SplArray forwards calls to sorting functions.
30 lines
487 B
PHP
30 lines
487 B
PHP
--TEST--
|
|
Crash when function parameter modified via reference
|
|
--FILE--
|
|
<?php
|
|
function usercompare($a,$b) {
|
|
unset($GLOBALS['my_var'][2]);
|
|
return $a <=> $b;
|
|
}
|
|
$my_var = array(1 => "entry_1",
|
|
2 => "entry_2",
|
|
3 => "entry_3",
|
|
4 => "entry_4",
|
|
5 => "entry_5");
|
|
usort($my_var, "usercompare");
|
|
var_dump($my_var);
|
|
|
|
?>
|
|
--EXPECT--
|
|
array(5) {
|
|
[0]=>
|
|
string(7) "entry_1"
|
|
[1]=>
|
|
string(7) "entry_2"
|
|
[2]=>
|
|
string(7) "entry_3"
|
|
[3]=>
|
|
string(7) "entry_4"
|
|
[4]=>
|
|
string(7) "entry_5"
|
|
}
|