diff options
author | Nikita Popov <nikic@php.net> | 2016-02-22 12:33:41 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-02-22 12:35:00 +0100 |
commit | fd6ac610641e48db1352c12de022500dd0272963 (patch) | |
tree | 3f8ab19aa33f24fa7a614c7709db1b6c2277988e | |
parent | 32e2801ff9878a928311a2d8a4599397a765c565 (diff) | |
download | php-git-fd6ac610641e48db1352c12de022500dd0272963.tar.gz |
Fix ArrayObject clone for certain USE_OTHER cases
We can't simply use HASH_OF, need to use the usual hash table
getter.
-rw-r--r-- | ext/spl/spl_array.c | 3 | ||||
-rw-r--r-- | ext/spl/tests/ArrayObject_clone_other_std_props.phpt | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 83c1f288ff..d3603a3b32 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -167,7 +167,8 @@ static zend_object *spl_array_object_new_ex(zend_class_entry *class_type, zval * if (other->ar_flags & SPL_ARRAY_IS_SELF) { ZVAL_UNDEF(&intern->array); } else if (Z_OBJ_HT_P(orig) == &spl_handler_ArrayObject) { - ZVAL_ARR(&intern->array, zend_array_dup(HASH_OF(&other->array))); + ZVAL_ARR(&intern->array, + zend_array_dup(spl_array_get_hash_table(&other->array, 0))); } else { ZEND_ASSERT(Z_OBJ_HT_P(orig) == &spl_handler_ArrayIterator); ZVAL_COPY(&intern->array, orig); diff --git a/ext/spl/tests/ArrayObject_clone_other_std_props.phpt b/ext/spl/tests/ArrayObject_clone_other_std_props.phpt new file mode 100644 index 0000000000..688954c3d7 --- /dev/null +++ b/ext/spl/tests/ArrayObject_clone_other_std_props.phpt @@ -0,0 +1,23 @@ +--TEST-- +Clone ArrayObject using other with STD_PROP_LIST +--FILE-- +<?php + +$a = new ArrayObject([1, 2, 3], ArrayObject::STD_PROP_LIST); +$b = new ArrayObject($a); +$c = clone $b; +var_dump($c); + +?> +--EXPECT-- +object(ArrayObject)#3 (1) { + ["storage":"ArrayObject":private]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} |