Skip to content

Commit 7d4e3dc

Browse files
committed
Promote warnings to errors in array_combine()
1 parent eaf66df commit 7d4e3dc

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,7 +6403,7 @@ PHP_FUNCTION(array_chunk)
64036403
}
64046404
/* }}} */
64056405

6406-
/* {{{ proto array|false array_combine(array keys, array values)
6406+
/* {{{ proto array array_combine(array keys, array values)
64076407
Creates an array by using the elements of the first parameter as keys and the elements of the second as the corresponding values */
64086408
PHP_FUNCTION(array_combine)
64096409
{
@@ -6421,8 +6421,8 @@ PHP_FUNCTION(array_combine)
64216421
num_values = zend_hash_num_elements(values);
64226422

64236423
if (num_keys != num_values) {
6424-
php_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements");
6425-
RETURN_FALSE;
6424+
zend_throw_error(NULL, "Both parameters should have an equal number of elements");
6425+
return;
64266426
}
64276427

64286428
if (!num_keys) {

ext/standard/tests/array/array_combine_error2.phpt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,42 @@ var_dump( array_combine(array(), array()) );
1616

1717
// Testing array_combine by passing empty array to $keys
1818
echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n";
19-
var_dump( array_combine(array(), array(1, 2)) );
19+
try {
20+
var_dump( array_combine(array(), array(1, 2)) );
21+
} catch (\Error $e) {
22+
echo $e->getMessage();
23+
}
2024

2125
// Testing array_combine by passing empty array to $values
2226
echo "\n-- Testing array_combine() function with empty array for \$values argument --\n";
23-
var_dump( array_combine(array(1, 2), array()) );
27+
try {
28+
var_dump( array_combine(array(1, 2), array()) );
29+
} catch (\Error $e) {
30+
echo $e->getMessage();
31+
}
2432

2533
// Testing array_combine with arrays having unequal number of elements
2634
echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n";
27-
var_dump( array_combine(array(1, 2), array(1, 2, 3)) );
35+
try {
36+
var_dump( array_combine(array(1, 2), array(1, 2, 3)) );
37+
} catch (\Error $e) {
38+
echo $e->getMessage();
39+
}
2840

29-
echo "Done";
3041
?>
31-
--EXPECTF--
42+
43+
DONE
44+
--EXPECT--
3245
*** Testing array_combine() : error conditions specific to array_combine() ***
3346

3447
-- Testing array_combine() function with empty arrays --
3548
array(0) {
3649
}
3750

3851
-- Testing array_combine() function with empty array for $keys argument --
39-
40-
Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d
41-
bool(false)
42-
52+
Both parameters should have an equal number of elements
4353
-- Testing array_combine() function with empty array for $values argument --
44-
45-
Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d
46-
bool(false)
47-
54+
Both parameters should have an equal number of elements
4855
-- Testing array_combine() function by passing array with unequal number of elements --
49-
50-
Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d
51-
bool(false)
52-
Done
56+
Both parameters should have an equal number of elements
57+
DONE

0 commit comments

Comments
 (0)