From: Nikita Popov Date: Wed, 5 Jun 2019 12:56:32 +0000 (+0200) Subject: Make sure array_splice() always returns an array X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3ed9d819297b6d9cf52f9d1c68ec64608d60aa7;p=php Make sure array_splice() always returns an array Return an array even if the return value isn't used. This allows us to add the arginfo return type. --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 654906253f..53673c371e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -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 */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 5ffab56d1c..ff5f11de4a 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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)