php-src/ext/standard/tests/array/array_user_key_compare.phpt
Nikita Popov dadb92ea35 Don't allow separation in array functions
The only case here that might be *somewhat* sensible is the userdata
argument of array_walk(), which could be used to keep persistent state
between callback invokations -- with the WTF moment that the final
result after the walk finishes will be unchanged. Nowdays, this is
much better achieved using a closure with a use-by-reference.
2020-07-07 09:15:43 +02:00

22 lines
494 B
PHP

--TEST--
Fix UMR in array_user_key_compare (MOPB24)
--FILE--
<?php
$arr = array("A" => 1, "B" => 1);
function array_compare(&$key1, &$key2)
{
$GLOBALS['a'] = &$key2;
unset($key2);
return 1;
}
uksort($arr, "array_compare");
var_dump($a);
?>
--EXPECTF--
Warning: array_compare(): Argument #1 ($key1) must be passed by reference, value given in %s on line %d
Warning: array_compare(): Argument #2 ($key2) must be passed by reference, value given in %s on line %d
string(1) "B"