RFC: https://wiki.php.net/rfc/custom_object_serialization
+ . array_merge() and array_merge_recursive() may now be called without any
+ arguments, in which case they will return an empty array. This is useful
+ in conjunction with the spread operator, e.g. array_merge(...$arrays).
+
========================================
3. Changes in SAPI modules
========================================
HashTable *src, *dest;
uint32_t count = 0;
- ZEND_PARSE_PARAMETERS_START(1, -1)
+ ZEND_PARSE_PARAMETERS_START(0, -1)
Z_PARAM_VARIADIC('+', args, argc)
ZEND_PARSE_PARAMETERS_END();
+ if (argc == 0) {
+ RETURN_EMPTY_ARRAY();
+ }
+
for (i = 0; i < argc; i++) {
zval *arg = args + i;
}
/* }}} */
-/* {{{ proto array array_merge(array arr1 [, array ...])
+/* {{{ proto array array_merge([array ...])
Merges elements from passed arrays into one array */
PHP_FUNCTION(array_merge)
{
}
/* }}} */
-/* {{{ proto array array_merge_recursive(array arr1 [, array ...])
+/* {{{ proto array array_merge_recursive([array ...])
Recursively merges elements from passed arrays into one array */
PHP_FUNCTION(array_merge_recursive)
{
ZEND_ARG_INFO(0, preserve_keys)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge, 0, 0, 1)
- ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge, 0, 0, 0)
ZEND_ARG_VARIADIC_INFO(0, arrays)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge_recursive, 0, 0, 1)
- ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge_recursive, 0, 0, 0)
ZEND_ARG_VARIADIC_INFO(0, arrays)
ZEND_END_ARG_INFO()
echo "\n*** Testing error conditions ***";
/* Invalid arguments */
-var_dump(array_merge());
var_dump(array_merge(100, 200));
var_dump(array_merge($begin_array[0], $begin_array[1], 100));
var_dump(array_merge($begin_array[0], $begin_array[1], $arr4));
+echo "\n*** Testing array_merge without any arguments ***\n";
+var_dump(array_merge());
+
echo "Done\n";
?>
--EXPECTF--
}
*** Testing error conditions ***
-Warning: array_merge() expects at least 1 parameter, 0 given in %s on line %d
-NULL
-
Warning: array_merge(): Expected parameter 1 to be an array, int given in %s on line %d
NULL
Warning: array_merge(): Expected parameter 3 to be an array, null given in %s on line %d
NULL
+
+*** Testing array_merge without any arguments ***
+array(0) {
+}
Done
$arr2 = array(3, array("hello", 'world'));
$arr3 = array(array(6, 7), array("str1", 'str2'));
+// Calling array_merge_recursive() without arguments
+echo "-- Without arguments --\n";
+var_dump( array_merge_recursive() );
+
// Calling array_merge_recursive() with default arguments
echo "-- With default argument --\n";
var_dump( array_merge_recursive($arr1) );
?>
--EXPECT--
*** Testing array_merge_recursive() : array with default keys ***
+-- Without arguments --
+array(0) {
+}
-- With default argument --
array(2) {
[0]=>
+++ /dev/null
---TEST--
-Test array_merge_recursive() function : error conditions
---FILE--
-<?php
-/* Prototype : array array_merge_recursive(array $arr1[, array $...])
- * Description: Recursively merges elements from passed arrays into one array
- * Source code: ext/standard/array.c
- */
-
-echo "*** Testing array_merge_recursive() : error conditions ***\n";
-
-// Zero arguments
-echo "\n-- Testing array_merge_recursive() function with Zero arguments --\n";
-var_dump( array_merge_recursive() );
-
-echo "Done";
-?>
---EXPECTF--
-*** Testing array_merge_recursive() : error conditions ***
-
--- Testing array_merge_recursive() function with Zero arguments --
-
-Warning: array_merge_recursive() expects at least 1 parameter, 0 given in %s on line %d
-NULL
-Done