diff options
author | timurib <timok@ya.ru> | 2018-01-07 18:10:12 +0300 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2018-03-25 17:49:04 +0200 |
commit | f7f48643e779111b23b546689b9fbb4e3affe1e7 (patch) | |
tree | 90f033a595385c272e19d6f4a3152348898f0503 | |
parent | 4be28e3f8ec9c3008120eecf98915fadc54d44bd (diff) | |
download | php-git-f7f48643e779111b23b546689b9fbb4e3affe1e7.tar.gz |
Remove redundant warning in array_push() and array_unshift()
Cf. https://github.com/php/php-src/pull/3011.
-rw-r--r-- | UPGRADING | 2 | ||||
-rw-r--r-- | ext/standard/array.c | 4 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 4 | ||||
-rw-r--r-- | ext/standard/tests/array/array_push.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/array/array_push_empty.phpt | 30 | ||||
-rw-r--r-- | ext/standard/tests/array/array_push_error1.phpt | 7 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unshift_empty.phpt | 30 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unshift_error.phpt | 14 |
8 files changed, 72 insertions, 21 deletions
@@ -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-- +<?php +/* Prototype : int array_push(array $stack[, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +$array = [1,2,3]; +$values = []; + +var_dump( array_push($array) ); +var_dump( array_push($array, ...$values) ); +var_dump( $array ); + +echo "Done"; +?> +--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-- <?php -/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) +/* Prototype : int array_push(array $stack[, mixed $...]) * Description: Pushes elements onto the end of the array * Source code: ext/standard/array.c */ @@ -15,8 +15,7 @@ echo "*** Testing array_push() : error conditions ***\n"; // Testing array_push with one less than the expected number of arguments echo "\n-- Testing array_push() function with less than expected no. of arguments --\n"; -$stack = array(1, 2); -var_dump( array_push($stack) ); +var_dump( array_push() ); echo "Done"; ?> @@ -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-- +<?php +/* Prototype : int array_unshift(array $array[, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +$array = [1,2,3]; +$values = []; + +var_dump( array_unshift($array) ); +var_dump( array_unshift($array, ...$values) ); +var_dump( $array ); + +echo "Done"; +?> +--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-- <?php -/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) +/* Prototype : int array_unshift(array $array[, mixed ...]) * Description: Pushes elements onto the beginning of the array * Source code: ext/standard/array.c */ @@ -12,11 +12,6 @@ echo "*** Testing array_unshift() : error conditions ***\n"; // Zero arguments echo "\n-- Testing array_unshift() function with Zero arguments --\n"; var_dump( array_unshift() ); - -// Testing array_unshift with one less than the expected number of arguments -echo "\n-- Testing array_unshift() function with less than expected no. of arguments --\n"; -$array = array(1, 2); -var_dump( array_unshift($array) ); echo "Done"; ?> --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 |