]> granicus.if.org Git - php/commitdiff
array_slice() passthrough for preserve_keys=true as well
authorSara Golemon <pollita@php.net>
Fri, 27 Oct 2017 14:13:17 +0000 (10:13 -0400)
committerSara Golemon <pollita@php.net>
Fri, 27 Oct 2017 14:14:03 +0000 (10:14 -0400)
ext/standard/array.c

index 89f0370461c22fd2d583e46ee28c8260d09ac004..ba09225f795ce37fbae9ff1b275bea45a96e0238 100644 (file)
@@ -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 */