Skip to content

Commit f7f4864

Browse files
timuribcmb69
authored andcommitted
Remove redundant warning in array_push() and array_unshift()
Cf. #3011.
1 parent 4be28e3 commit f7f4864

File tree

8 files changed

+72
-21
lines changed

8 files changed

+72
-21
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ JSON:
8787
Standard:
8888
. debug_zval_dump() was changed to display recursive arrays and objects
8989
in the same way as var_dump(). Now, it doesn't display them twice.
90+
. array_push() and array_unshift() can now also be called with a single
91+
argument, which is particularly convenient wrt. the spread operator.
9092

9193
PCRE:
9294
. preg_quote() now also escapes the '#' character.

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,7 +3217,7 @@ PHP_FUNCTION(array_push)
32173217
argc; /* Number of function arguments */
32183218

32193219

3220-
ZEND_PARSE_PARAMETERS_START(2, -1)
3220+
ZEND_PARSE_PARAMETERS_START(1, -1)
32213221
Z_PARAM_ARRAY_EX(stack, 0, 1)
32223222
Z_PARAM_VARIADIC('+', args, argc)
32233223
ZEND_PARSE_PARAMETERS_END();
@@ -3417,7 +3417,7 @@ PHP_FUNCTION(array_unshift)
34173417
zend_string *key;
34183418
zval *value;
34193419

3420-
ZEND_PARSE_PARAMETERS_START(2, -1)
3420+
ZEND_PARSE_PARAMETERS_START(1, -1)
34213421
Z_PARAM_ARRAY_EX(stack, 0, 1)
34223422
Z_PARAM_VARIADIC('+', args, argc)
34233423
ZEND_PARSE_PARAMETERS_END();

ext/standard/basic_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_shuffle, 0)
360360
ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */
361361
ZEND_END_ARG_INFO()
362362

363-
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 2)
363+
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 1)
364364
ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */
365365
ZEND_ARG_VARIADIC_INFO(0, vars)
366366
ZEND_END_ARG_INFO()
@@ -373,7 +373,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_shift, 0)
373373
ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */
374374
ZEND_END_ARG_INFO()
375375

376-
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 2)
376+
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 1)
377377
ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */
378378
ZEND_ARG_VARIADIC_INFO(0, vars)
379379
ZEND_END_ARG_INFO()

ext/standard/tests/array/array_push.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ echo"\nDone";
7272
--EXPECTF--
7373
*** Testing Error Conditions ***
7474

75-
Warning: array_push() expects at least 2 parameters, 0 given in %s on line %d
75+
Warning: array_push() expects at least 1 parameter, 0 given in %s on line %d
7676
NULL
7777

7878
Warning: array_push() expects parameter 1 to be array, int given in %s on line %d
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test array_push() function : push empty set to the array
3+
--FILE--
4+
<?php
5+
/* Prototype : int array_push(array $stack[, mixed $...])
6+
* Description: Pushes elements onto the end of the array
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
$array = [1,2,3];
11+
$values = [];
12+
13+
var_dump( array_push($array) );
14+
var_dump( array_push($array, ...$values) );
15+
var_dump( $array );
16+
17+
echo "Done";
18+
?>
19+
--EXPECTF--
20+
int(3)
21+
int(3)
22+
array(3) {
23+
[0]=>
24+
int(1)
25+
[1]=>
26+
int(2)
27+
[2]=>
28+
int(3)
29+
}
30+
Done

ext/standard/tests/array/array_push_error1.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test array_push() function : error conditions - Pass incorrect number of args
33
--FILE--
44
<?php
5-
/* Prototype : int array_push(array $stack, mixed $var [, mixed $...])
5+
/* Prototype : int array_push(array $stack[, mixed $...])
66
* Description: Pushes elements onto the end of the array
77
* Source code: ext/standard/array.c
88
*/
@@ -15,8 +15,7 @@ echo "*** Testing array_push() : error conditions ***\n";
1515

1616
// Testing array_push with one less than the expected number of arguments
1717
echo "\n-- Testing array_push() function with less than expected no. of arguments --\n";
18-
$stack = array(1, 2);
19-
var_dump( array_push($stack) );
18+
var_dump( array_push() );
2019

2120
echo "Done";
2221
?>
@@ -25,6 +24,6 @@ echo "Done";
2524

2625
-- Testing array_push() function with less than expected no. of arguments --
2726

28-
Warning: array_push() expects at least 2 parameters, 1 given in %s on line %d
27+
Warning: array_push() expects at least 1 parameter, 0 given in %s on line %d
2928
NULL
3029
Done
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test array_unshift() function : prepend array with empty set
3+
--FILE--
4+
<?php
5+
/* Prototype : int array_unshift(array $array[, mixed ...])
6+
* Description: Pushes elements onto the beginning of the array
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
$array = [1,2,3];
11+
$values = [];
12+
13+
var_dump( array_unshift($array) );
14+
var_dump( array_unshift($array, ...$values) );
15+
var_dump( $array );
16+
17+
echo "Done";
18+
?>
19+
--EXPECTF--
20+
int(3)
21+
int(3)
22+
array(3) {
23+
[0]=>
24+
int(1)
25+
[1]=>
26+
int(2)
27+
[2]=>
28+
int(3)
29+
}
30+
Done

ext/standard/tests/array/array_unshift_error.phpt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test array_unshift() function : error conditions
33
--FILE--
44
<?php
5-
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
5+
/* Prototype : int array_unshift(array $array[, mixed ...])
66
* Description: Pushes elements onto the beginning of the array
77
* Source code: ext/standard/array.c
88
*/
@@ -12,23 +12,13 @@ echo "*** Testing array_unshift() : error conditions ***\n";
1212
// Zero arguments
1313
echo "\n-- Testing array_unshift() function with Zero arguments --\n";
1414
var_dump( array_unshift() );
15-
16-
// Testing array_unshift with one less than the expected number of arguments
17-
echo "\n-- Testing array_unshift() function with less than expected no. of arguments --\n";
18-
$array = array(1, 2);
19-
var_dump( array_unshift($array) );
2015
echo "Done";
2116
?>
2217
--EXPECTF--
2318
*** Testing array_unshift() : error conditions ***
2419

2520
-- Testing array_unshift() function with Zero arguments --
2621

27-
Warning: array_unshift() expects at least 2 parameters, 0 given in %s on line %d
28-
NULL
29-
30-
-- Testing array_unshift() function with less than expected no. of arguments --
31-
32-
Warning: array_unshift() expects at least 2 parameters, 1 given in %s on line %d
22+
Warning: array_unshift() expects at least 1 parameter, 0 given in %s on line %d
3323
NULL
3424
Done

0 commit comments

Comments
 (0)