Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,10 @@ static zend_result spl_array_skip_protected(spl_array_object *intern, HashTable
static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, bool just_array) {
/* Handled by ZPP prior to this, or for __unserialize() before passing to here */
ZEND_ASSERT(Z_TYPE_P(array) == IS_ARRAY || Z_TYPE_P(array) == IS_OBJECT);
if (intern->nApplyCount > 0) {
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
return;
}
zval garbage;
ZVAL_UNDEF(&garbage);
if (Z_TYPE_P(array) == IS_ARRAY) {
Expand Down
34 changes: 34 additions & 0 deletions ext/spl/tests/ArrayObject_construct_during_sorting.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Can't use __construct() to replace the backing store while ArrayObject is being sorted
--FILE--
<?php

$ao = new ArrayObject([1, 2, 3]);
$other = new ArrayObject([4, 5, 6]);
$i = 0;
$ao->uasort(function($a, $b) use ($ao, $other, &$i) {
if ($i++ == 0) {
try {
$ao->__construct($other);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
}
return $a <=> $b;
});
var_dump($ao);

?>
--EXPECT--
Modification of ArrayObject during sorting is prohibited
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
Loading