php-src/ext/standard/tests/array/unexpected_array_mod_bug_variation1.phpt
Nikita Popov b1e854f776 Fix bug #71334
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.
2016-03-30 22:49:27 +02:00

33 lines
541 B
PHP

--TEST--
Crash when function parameter modified via reference while keeping orig refcount
--FILE--
<?php
$array = array(
1 => "entry_1",
2 => "entry_2",
3 => "entry_3",
4 => "entry_4",
5 => "entry_5"
);
usort($array, function($a, $b) use (&$array, &$ref) {
unset($array[2]);
$ref = $array;
return $a <=> $b;
});
var_dump($array);
?>
--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"
}