We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4be28e3 commit f7f4864Copy full SHA for f7f4864
UPGRADING
@@ -87,6 +87,8 @@ JSON:
87
Standard:
88
. debug_zval_dump() was changed to display recursive arrays and objects
89
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.
92
93
PCRE:
94
. preg_quote() now also escapes the '#' character.
ext/standard/array.c
@@ -3217,7 +3217,7 @@ PHP_FUNCTION(array_push)
3217
argc; /* Number of function arguments */
3218
3219
3220
- ZEND_PARSE_PARAMETERS_START(2, -1)
+ ZEND_PARSE_PARAMETERS_START(1, -1)
3221
Z_PARAM_ARRAY_EX(stack, 0, 1)
3222
Z_PARAM_VARIADIC('+', args, argc)
3223
ZEND_PARSE_PARAMETERS_END();
@@ -3417,7 +3417,7 @@ PHP_FUNCTION(array_unshift)
3417
zend_string *key;
3418
zval *value;
3419
3420
3421
3422
3423
ext/standard/basic_functions.c
@@ -360,7 +360,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_shuffle, 0)
360
ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */
361
ZEND_END_ARG_INFO()
362
363
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 2)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 1)
364
ZEND_ARG_INFO(1, stack) /* ARRAY_INFO(1, stack, 0) */
365
ZEND_ARG_VARIADIC_INFO(0, vars)
366
@@ -373,7 +373,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_shift, 0)
373
374
375
376
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 2)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_array_unshift, 0, 0, 1)
377
378
379
ext/standard/tests/array/array_push.phpt
@@ -72,7 +72,7 @@ echo"\nDone";
72
--EXPECTF--
73
*** Testing Error Conditions ***
74
75
-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
76
NULL
77
78
Warning: array_push() expects parameter 1 to be array, int given in %s on line %d
ext/standard/tests/array/array_push_empty.phpt
@@ -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
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
@@ -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 $...])
* 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
Done
ext/standard/tests/array/array_unshift_empty.phpt
+Test array_unshift() function : prepend array with empty set
+/* Prototype : int array_unshift(array $array[, mixed ...])
+ * Description: Pushes elements onto the beginning of the array
+*/
+var_dump( array_unshift($array) );
+var_dump( array_unshift($array, ...$values) );
ext/standard/tests/array/array_unshift_error.phpt
Test array_unshift() function : error conditions
-/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
@@ -12,23 +12,13 @@ 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) );
*** Testing array_unshift() : error conditions ***
-- 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 --
31
32
-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
33
34
0 commit comments