com php-src: Promote warnings to errors in array_combine( ): ext/standard/array.c ext/standard/tests/array/arra y_combine_error2.phpt

From: Date: Wed, 21 Aug 2019 16:12:56 +0000
Subject: com php-src: Promote warnings to errors in array_combine( ): ext/standard/array.c ext/standard/tests/array/arra y_combine_error2.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-107983@lists.php.net to get a copy of this message
Commit: 7d4e3dc32d5bcf386f53607b3190e9a856844ad1 Author: George Peter Banyard <girgias@php.net> Wed, 21 Aug 2019 02:18:00 +0200 Parents: eaf66df51748beb3df5c2431262ebaa76578ebf1 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7d4e3dc32d5bcf386f53607b3190e9a856844ad1 Log: Promote warnings to errors in array_combine() Changed paths: M ext/standard/array.c M ext/standard/tests/array/array_combine_error2.phpt Diff: diff --git a/ext/standard/array.c b/ext/standard/array.c index aca24a4..164b7da 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -6403,7 +6403,7 @@ PHP_FUNCTION(array_chunk) } /* }}} */ -/* {{{ proto array|false array_combine(array keys, array values) +/* {{{ proto array array_combine(array keys, array values) Creates an array by using the elements of the first parameter as keys and the elements of the second as the corresponding values */ PHP_FUNCTION(array_combine) { @@ -6421,8 +6421,8 @@ PHP_FUNCTION(array_combine) num_values = zend_hash_num_elements(values); if (num_keys != num_values) { - php_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements"); - RETURN_FALSE; + zend_throw_error(NULL, "Both parameters should have an equal number of elements"); + return; } if (!num_keys) { diff --git a/ext/standard/tests/array/array_combine_error2.phpt b/ext/standard/tests/array/array_combine_error2.phpt index 2d820a0..463dc6d 100644 --- a/ext/standard/tests/array/array_combine_error2.phpt +++ b/ext/standard/tests/array/array_combine_error2.phpt @@ -16,19 +16,32 @@ var_dump( array_combine(array(), array()) ); // Testing array_combine by passing empty array to $keys echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n"; -var_dump( array_combine(array(), array(1, 2)) ); +try { + var_dump( array_combine(array(), array(1, 2)) ); +} catch (\Error $e) { + echo $e->getMessage(); +} // Testing array_combine by passing empty array to $values echo "\n-- Testing array_combine() function with empty array for \$values argument --\n"; -var_dump( array_combine(array(1, 2), array()) ); +try { + var_dump( array_combine(array(1, 2), array()) ); +} catch (\Error $e) { + echo $e->getMessage(); +} // Testing array_combine with arrays having unequal number of elements echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n"; -var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); +try { + var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); +} catch (\Error $e) { + echo $e->getMessage(); +} -echo "Done"; ?> ---EXPECTF-- + +DONE +--EXPECT-- *** Testing array_combine() : error conditions specific to array_combine() *** -- Testing array_combine() function with empty arrays -- @@ -36,17 +49,9 @@ array(0) { } -- Testing array_combine() function with empty array for $keys argument -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) - +Both parameters should have an equal number of elements -- Testing array_combine() function with empty array for $values argument -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) - +Both parameters should have an equal number of elements -- Testing array_combine() function by passing array with unequal number of elements -- - -Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d -bool(false) -Done +Both parameters should have an equal number of elements +DONE

« previous php.cvs (#107983) next »