]> granicus.if.org Git - php/commitdiff
Make sure array_splice() always returns an array
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 5 Jun 2019 12:56:32 +0000 (14:56 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 5 Jun 2019 12:56:32 +0000 (14:56 +0200)
Return an array even if the return value isn't used. This allows us
to add the arginfo return type.

ext/standard/array.c
ext/standard/basic_functions.c

index 654906253fc1515abdb0aaba0bb4153873019005..53673c371e81e2939942246b4331899b5423a9a1 100644 (file)
@@ -3382,7 +3382,7 @@ PHP_FUNCTION(array_unshift)
 }
 /* }}} */
 
-/* {{{ proto array|null array_splice(array input, int offset [, int length [, array replacement]])
+/* {{{ proto array array_splice(array input, int offset [, int length [, array replacement]])
    Removes the elements designated by offset and length and replace them with supplied array */
 PHP_FUNCTION(array_splice)
 {
@@ -3434,6 +3434,9 @@ PHP_FUNCTION(array_splice)
                /* Initialize return value */
                array_init_size(return_value, size > 0 ? (uint32_t)size : 0);
                rem_hash = Z_ARRVAL_P(return_value);
+       } else {
+               /* The return value will not be used, but make sure it still has the correct type. */
+               RETVAL_EMPTY_ARRAY();
        }
 
        /* Perform splice */
index 5ffab56d1cdd990160a8edaf36227dcc5957208a..ff5f11de4a598d553779238b1ae354d1ceecfdf3 100644 (file)
@@ -365,7 +365,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_unshift, 0, 1, IS_LONG, 0)
        ZEND_ARG_VARIADIC_INFO(0, vars)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_splice, 0, 0, 2)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_splice, 0, 2, IS_ARRAY, 0)
        ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */
        ZEND_ARG_INFO(0, offset)
        ZEND_ARG_INFO(0, length)