Skip to content

Commit f33837f

Browse files
committed
Implemented request #34857 (Change array_combine behaviour when called with
empty arrays). Patch by Joel Perras <joel.perras@gmail.com>.
1 parent 0f34683 commit f33837f

7 files changed

+15
-17
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
at gmail dot com, Pierre)
102102
- Implemented FR #42060 (Add paged Results support). (ando@OpenLDAP.org,
103103
iarenuno@eteo.mondragon.edu, jeanseb@au-fil-du.net, remy.saissy@gmail.com)
104+
- Implemented FR #34857 (Change array_combine behaviour when called with empty
105+
arrays). (joel.perras@gmail.com)
104106

105107
- Fixed PDO objects binary incompatibility. (Dmitry)
106108

UPGRADING

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ UPGRADE NOTES - PHP X.Y
9090
3. Changes made to existing functions
9191
=====================================
9292

93-
-
93+
- array_combine now returns array() instead of FALSE when two empty arrays are
94+
provided as parameters.
9495

9596
===================================
9697
4. Changes made to existing methods

ext/standard/array.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -4481,13 +4481,12 @@ PHP_FUNCTION(array_combine)
44814481
RETURN_FALSE;
44824482
}
44834483

4484+
array_init_size(return_value, num_keys);
4485+
44844486
if (!num_keys) {
4485-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Both parameters should have at least 1 element");
4486-
RETURN_FALSE;
4487+
return;
44874488
}
44884489

4489-
array_init_size(return_value, num_keys);
4490-
44914490
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &pos_keys);
44924491
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
44934492
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)&entry_keys, &pos_keys) == SUCCESS &&

ext/standard/tests/array/array_combine_error2.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ echo "Done";
3232
*** Testing array_combine() : error conditions specific to array_combine() ***
3333

3434
-- Testing array_combine() function with empty arrays --
35-
36-
Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d
37-
bool(false)
35+
array(0) {
36+
}
3837

3938
-- Testing array_combine() function with empty array for $keys argument --
4039

ext/standard/tests/array/array_combine_variation3.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ array(2) {
108108
bool(true)
109109
}
110110
-- Iteration 4 --
111-
112-
Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d
113-
bool(false)
111+
array(0) {
112+
}
114113
-- Iteration 5 --
115114
array(1) {
116115
[""]=>

ext/standard/tests/array/array_combine_variation4.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ Warning: Illegal offset type in %s on line %d
100100

101101
Warning: Illegal offset type in %s on line %d
102102
-- Iteration 1 --
103-
104-
Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d
105-
bool(false)
103+
array(0) {
104+
}
106105
-- Iteration 2 --
107106
array(1) {
108107
[0]=>

ext/standard/tests/array/array_combine_variation5.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ echo "Done";
8282
--EXPECTF--
8383
*** Testing array_combine() : assoc array with diff values to both $keys and $values argument ***
8484
-- Iteration 1 --
85-
86-
Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d
87-
bool(false)
85+
array(0) {
86+
}
8887
-- Iteration 2 --
8988
array(1) {
9089
[0]=>

0 commit comments

Comments
 (0)