}
zval_ptr_dtor(&tmp);
} else {
- if (Z_REFCOUNTED_P(src_entry)) {
- Z_ADDREF_P(src_entry);
- }
- zend_hash_add_new(dest, string_key, src_entry);
+ zval *zv = zend_hash_add_new(dest, string_key, src_entry);
+ zval_add_ref(zv);
}
} else {
- if (Z_REFCOUNTED_P(src_entry)) {
- Z_ADDREF_P(src_entry);
- }
- zend_hash_next_index_insert_new(dest, src_entry);
+ zval *zv = zend_hash_next_index_insert_new(dest, src_entry);
+ zval_add_ref(zv);
}
} ZEND_HASH_FOREACH_END();
return 1;
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
- if (Z_REFCOUNTED_P(src_entry)) {
- Z_ADDREF_P(src_entry);
- }
- zend_hash_update(dest, string_key, src_entry);
-
+ zval *zv = zend_hash_update(dest, string_key, src_entry);
+ zval_add_ref(zv);
continue;
}
} else {
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
- if (Z_REFCOUNTED_P(src_entry)) {
- Z_ADDREF_P(src_entry);
- }
- zend_hash_index_update(dest, num_key, src_entry);
-
+ zval *zv = zend_hash_index_update(dest, num_key, src_entry);
+ zval_add_ref(zv);
continue;
}
}
--- /dev/null
+--TEST--
+array_merge/replace_recursive() should unwrap references with rc=1
+--FILE--
+<?php
+
+$x = 24;
+$arr1 = [[42]];
+$arr2 = [[&$x]];
+unset($x);
+$arr3 = array_replace_recursive($arr1, $arr2);
+$arr2[0][0] = 12;
+var_dump($arr3);
+
+unset($arr1, $arr2, $arr3);
+
+$x = 24;
+$arr1 = [42];
+$arr2 = [&$x];
+unset($x);
+$arr3 = array_merge_recursive($arr1, $arr2);
+$arr2[0] = 12;
+var_dump($arr3);
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(1) {
+ [0]=>
+ int(24)
+ }
+}
+array(2) {
+ [0]=>
+ int(42)
+ [1]=>
+ int(24)
+}