Cf. https://github.com/php/php-src/pull/3011.
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.
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();
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();
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()
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()
--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
--- /dev/null
+--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
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
*/
// 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";
?>
-- 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
--- /dev/null
+--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
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
*/
// 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--
-- 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