Skip to content

Commit 939e109

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys)
2 parents 011be49 + 6531719 commit 939e109

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
@@ -3666,10 +3666,6 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
36663666
if (Z_TYPE_P(dest_zval) == IS_NULL) {
36673667
convert_to_array_ex(dest_zval);
36683668
add_next_index_null(dest_zval);
3669-
} else if (Z_TYPE_P(dest_zval) == IS_ARRAY) {
3670-
if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement > (zend_long)Z_ARRVAL_P(dest_zval)->nNumUsed)) {
3671-
Z_ARRVAL_P(dest_zval)->nNextFreeElement = Z_ARRVAL_P(dest_zval)->nNumUsed;
3672-
}
36733669
} else {
36743670
convert_to_array_ex(dest_zval);
36753671
}
@@ -3702,7 +3698,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */
37023698
zval_add_ref(zv);
37033699
}
37043700
} else {
3705-
zval *zv = zend_hash_next_index_insert_new(dest, src_entry);
3701+
zval *zv = zend_hash_next_index_insert(dest, src_entry);
37063702
zval_add_ref(zv);
37073703
}
37083704
} 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)