Remove redundant warning in array_push() and array_unshift()

Cf. https://github.com/php/php-src/pull/3011.
This commit is contained in:
timurib 2018-01-07 18:10:12 +03:00 committed by Christoph M. Becker
parent 4be28e3f8e
commit f7f48643e7
8 changed files with 72 additions and 21 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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