From d3ed9d819297b6d9cf52f9d1c68ec64608d60aa7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 5 Jun 2019 14:56:32 +0200 Subject: [PATCH] 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. --- ext/standard/array.c | 5 ++++- ext/standard/basic_functions.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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) -- 2.50.1