From: Sara Golemon Date: Fri, 27 Oct 2017 14:13:17 +0000 (-0400) Subject: array_slice() passthrough for preserve_keys=true as well X-Git-Tag: php-7.3.0alpha1~1159^2~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fabb5b7a7421280b43e6f11c59d9446f6b21e3e6;p=php array_slice() passthrough for preserve_keys=true as well --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 89f0370461..ba09225f79 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3563,12 +3563,13 @@ PHP_FUNCTION(array_slice) return; } - if ((offset == 0) && (length >= num_in) && - HT_IS_PACKED(Z_ARRVAL_P(input)) && - HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(input))) { - /* No real slicing, and the keys will be 0..n-1, so just copy */ - ZVAL_COPY(return_value, input); - return; + if ((offset == 0) && (length >= num_in)) { + zend_array *ht = Z_ARRVAL_P(input); + if (preserve_keys || (HT_IS_PACKED(ht) && HT_IS_WITHOUT_HOLES(ht))) { + /* No real slicing, and the keys will match, so just copy */ + ZVAL_COPY(return_value, input); + return; + } } /* Initialize returned array */