mirror of
https://github.com/php/php-src.git
synced 2026-04-20 14:31:06 +02:00
Make user-exposed sorts stable, by storing the position of elements in the original array, and using those positions as a fallback comparison criterion. The base sort is still hybrid q/insert. The use of true/false comparison functions is deprecated (but still supported) and should be replaced by -1/0/1 comparison functions, driven by the <=> operator. RFC: https://wiki.php.net/rfc/stable_sorting Closes GH-5236.
16 lines
399 B
PHP
16 lines
399 B
PHP
--TEST--
|
|
Bug #67539 (ArrayIterator use-after-free due to object change during sorting)
|
|
--FILE--
|
|
<?php
|
|
|
|
$it = new ArrayIterator(array_fill(0,2,'X'), 1 );
|
|
|
|
function badsort($a, $b) {
|
|
$GLOBALS['it']->unserialize($GLOBALS['it']->serialize());
|
|
return 0;
|
|
}
|
|
|
|
$it->uksort('badsort');
|
|
--EXPECTF--
|
|
Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d
|