]> granicus.if.org Git - php/commitdiff
Fix ArrayObject clone for certain USE_OTHER cases
authorNikita Popov <nikic@php.net>
Mon, 22 Feb 2016 11:33:41 +0000 (12:33 +0100)
committerNikita Popov <nikic@php.net>
Mon, 22 Feb 2016 11:35:00 +0000 (12:35 +0100)
We can't simply use HASH_OF, need to use the usual hash table
getter.

ext/spl/spl_array.c
ext/spl/tests/ArrayObject_clone_other_std_props.phpt [new file with mode: 0644]

index 83c1f288ff34bd3e53eed0df5d91c3beb3f48d68..d3603a3b32bf8193d00bfcb45ddbf1310644e213 100644 (file)
@@ -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 (file)
index 0000000..688954c
--- /dev/null
@@ -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)
+  }
+}