Skip to content

Commit 220c882

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: [ci skip] NEWS for GH-16061 Fix array_merge_recursive(): convert_to_array() may need separation (#16061)
2 parents 0516d95 + 2bcf3f9 commit 220c882

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ext/standard/array.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3916,7 +3916,6 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
39163916
}
39173917

39183918
ZEND_ASSERT(!Z_ISREF_P(dest_entry) || Z_REFCOUNT_P(dest_entry) > 1);
3919-
SEPARATE_ZVAL(dest_entry);
39203919
dest_zval = dest_entry;
39213920

39223921
if (Z_TYPE_P(dest_zval) == IS_NULL) {
@@ -3925,6 +3924,8 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
39253924
} else {
39263925
convert_to_array(dest_zval);
39273926
}
3927+
SEPARATE_ZVAL(dest_zval);
3928+
39283929
ZVAL_UNDEF(&tmp);
39293930
if (Z_TYPE_P(src_zval) == IS_OBJECT) {
39303931
ZVAL_COPY(&tmp, src_zval);

ext/standard/tests/array/gh16053.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-16053: Assertion failure in Zend/zend_hash.c
3+
--FILE--
4+
<?php
5+
6+
class test
7+
{
8+
}
9+
$x = new test;
10+
$arr1 = array("string" => $x);
11+
$arr2 = array("string" => "hello");
12+
var_dump($arr1);
13+
var_dump(array_merge_recursive($arr1, $arr2));
14+
15+
?>
16+
--EXPECTF--
17+
array(1) {
18+
["string"]=>
19+
object(test)#%d (0) {
20+
}
21+
}
22+
array(1) {
23+
["string"]=>
24+
array(1) {
25+
[0]=>
26+
string(5) "hello"
27+
}
28+
}

0 commit comments

Comments
 (0)