From: timurib Date: Sun, 7 Jan 2018 15:10:12 +0000 (+0300) Subject: Remove redundant warning in array_push() and array_unshift() X-Git-Tag: php-7.3.0alpha1~132 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7f48643e779111b23b546689b9fbb4e3affe1e7;p=php Remove redundant warning in array_push() and array_unshift() Cf. https://github.com/php/php-src/pull/3011. --- diff --git a/UPGRADING b/UPGRADING index 44bcae469c..6729b745f1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -87,6 +87,8 @@ JSON: Standard: . debug_zval_dump() was changed to display recursive arrays and objects in the same way as var_dump(). Now, it doesn't display them twice. + . array_push() and array_unshift() can now also be called with a single + argument, which is particularly convenient wrt. the spread operator. PCRE: . preg_quote() now also escapes the '#' character. diff --git a/ext/standard/array.c b/ext/standard/array.c index bd8da682bd..4bc363bd19 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3217,7 +3217,7 @@ PHP_FUNCTION(array_push) argc; /* Number of function arguments */ - ZEND_PARSE_PARAMETERS_START(2, -1) + ZEND_PARSE_PARAMETERS_START(1, -1) Z_PARAM_ARRAY_EX(stack, 0, 1) Z_PARAM_VARIADIC('+', args, argc) ZEND_PARSE_PARAMETERS_END(); @@ -3417,7 +3417,7 @@ PHP_FUNCTION(array_unshift) zend_string *key; zval *value; - ZEND_PARSE_PARAMETERS_START(2, -1) + ZEND_PARSE_PARAMETERS_START(1, -1) Z_PARAM_ARRAY_EX(stack, 0, 1) Z_PARAM_VARIADIC('+', args, argc) ZEND_PARSE_PARAMETERS_END(); diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 95281705dc..01fb765be3 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -360,7 +360,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_shuffle, 0) ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 1) ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */ ZEND_ARG_VARIADIC_INFO(0, vars) ZEND_END_ARG_INFO() @@ -373,7 +373,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_shift, 0) ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 1) ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */ ZEND_ARG_VARIADIC_INFO(0, vars) ZEND_END_ARG_INFO() diff --git a/ext/standard/tests/array/array_push.phpt b/ext/standard/tests/array/array_push.phpt index 4d8a55e329..829100c54c 100644 --- a/ext/standard/tests/array/array_push.phpt +++ b/ext/standard/tests/array/array_push.phpt @@ -72,7 +72,7 @@ echo"\nDone"; --EXPECTF-- *** Testing Error Conditions *** -Warning: array_push() expects at least 2 parameters, 0 given in %s on line %d +Warning: array_push() expects at least 1 parameter, 0 given in %s on line %d NULL Warning: array_push() expects parameter 1 to be array, int given in %s on line %d diff --git a/ext/standard/tests/array/array_push_empty.phpt b/ext/standard/tests/array/array_push_empty.phpt new file mode 100644 index 0000000000..7ca7e7fdd2 --- /dev/null +++ b/ext/standard/tests/array/array_push_empty.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_push() function : push empty set to the array +--FILE-- + +--EXPECTF-- +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_push_error1.phpt b/ext/standard/tests/array/array_push_error1.phpt index fe26fb697e..ec866348b2 100644 --- a/ext/standard/tests/array/array_push_error1.phpt +++ b/ext/standard/tests/array/array_push_error1.phpt @@ -2,7 +2,7 @@ Test array_push() function : error conditions - Pass incorrect number of args --FILE-- @@ -25,6 +24,6 @@ echo "Done"; -- Testing array_push() function with less than expected no. of arguments -- -Warning: array_push() expects at least 2 parameters, 1 given in %s on line %d +Warning: array_push() expects at least 1 parameter, 0 given in %s on line %d NULL Done diff --git a/ext/standard/tests/array/array_unshift_empty.phpt b/ext/standard/tests/array/array_unshift_empty.phpt new file mode 100644 index 0000000000..546a24a98a --- /dev/null +++ b/ext/standard/tests/array/array_unshift_empty.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_unshift() function : prepend array with empty set +--FILE-- + +--EXPECTF-- +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_unshift_error.phpt b/ext/standard/tests/array/array_unshift_error.phpt index 1381111ec4..3eeb3eb750 100644 --- a/ext/standard/tests/array/array_unshift_error.phpt +++ b/ext/standard/tests/array/array_unshift_error.phpt @@ -2,7 +2,7 @@ Test array_unshift() function : error conditions --FILE-- --EXPECTF-- @@ -24,11 +19,6 @@ echo "Done"; -- Testing array_unshift() function with Zero arguments -- -Warning: array_unshift() expects at least 2 parameters, 0 given in %s on line %d -NULL - --- Testing array_unshift() function with less than expected no. of arguments -- - -Warning: array_unshift() expects at least 2 parameters, 1 given in %s on line %d +Warning: array_unshift() expects at least 1 parameter, 0 given in %s on line %d NULL Done