Skip to content

Commit 8b2f407

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Update NEWS Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys)
2 parents 3f53b02 + e62c6e7 commit 8b2f407

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

ext/standard/array.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,10 +3673,6 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
36733673
if (Z_TYPE_P(dest_zval) == IS_NULL) {
36743674
convert_to_array_ex(dest_zval);
36753675
add_next_index_null(dest_zval);
3676-
} else if (Z_TYPE_P(dest_zval) == IS_ARRAY) {
3677-
if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement > (zend_long)Z_ARRVAL_P(dest_zval)->nNumUsed)) {
3678-
Z_ARRVAL_P(dest_zval)->nNextFreeElement = Z_ARRVAL_P(dest_zval)->nNumUsed;
3679-
}
36803676
} else {
36813677
convert_to_array_ex(dest_zval);
36823678
}
@@ -3707,7 +3703,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
37073703
zval_add_ref(zv);
37083704
}
37093705
} else {
3710-
zval *zv = zend_hash_next_index_insert_new(dest, src_entry);
3706+
zval *zv = zend_hash_next_index_insert(dest, src_entry);
37113707
zval_add_ref(zv);
37123708
}
37133709
} ZEND_HASH_FOREACH_END();

ext/standard/tests/array/bug70808.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Array
1717
[key] => Array
1818
(
1919
[0] => 0
20-
[1] => 2
20+
[2] => 2
2121
)
2222

2323
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #76505 (array_merge_recursive() is duplicating sub-array keys)
3+
--FILE--
4+
<?php
5+
$array1 = array(
6+
'k' => array(
7+
2 => 100,
8+
98 => 200,
9+
)
10+
);
11+
12+
$array2 = array(
13+
'k' => array(
14+
64 => 300
15+
)
16+
);
17+
18+
$array3 = array_merge_recursive( $array1, $array2 );
19+
20+
var_dump($array3);
21+
?>
22+
--EXPECT--
23+
array(1) {
24+
["k"]=>
25+
array(3) {
26+
[2]=>
27+
int(100)
28+
[98]=>
29+
int(200)
30+
[99]=>
31+
int(300)
32+
}
33+
}

0 commit comments

Comments
 (0)