Skip to content

Commit d3ed9d8

Browse files
committed
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.
1 parent 7686b0b commit d3ed9d8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

ext/standard/array.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,7 @@ PHP_FUNCTION(array_unshift)
33823382
}
33833383
/* }}} */
33843384

3385-
/* {{{ proto array|null array_splice(array input, int offset [, int length [, array replacement]])
3385+
/* {{{ proto array array_splice(array input, int offset [, int length [, array replacement]])
33863386
Removes the elements designated by offset and length and replace them with supplied array */
33873387
PHP_FUNCTION(array_splice)
33883388
{
@@ -3434,6 +3434,9 @@ PHP_FUNCTION(array_splice)
34343434
/* Initialize return value */
34353435
array_init_size(return_value, size > 0 ? (uint32_t)size : 0);
34363436
rem_hash = Z_ARRVAL_P(return_value);
3437+
} else {
3438+
/* The return value will not be used, but make sure it still has the correct type. */
3439+
RETVAL_EMPTY_ARRAY();
34373440
}
34383441

34393442
/* Perform splice */

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_unshift, 0, 1, IS_LONG, 0)
365365
ZEND_ARG_VARIADIC_INFO(0, vars)
366366
ZEND_END_ARG_INFO()
367367

368-
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_splice, 0, 0, 2)
368+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_splice, 0, 2, IS_ARRAY, 0)
369369
ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */
370370
ZEND_ARG_INFO(0, offset)
371371
ZEND_ARG_INFO(0, length)

0 commit comments

Comments
 (0)