]> granicus.if.org Git - php/commitdiff
fix #43596 (array_slice(): $length arg ignored when it is 0)
authorAntony Dovgal <tony2001@php.net>
Tue, 29 Jan 2008 00:39:26 +0000 (00:39 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 29 Jan 2008 00:39:26 +0000 (00:39 +0000)
ext/standard/array.c

index 303bf582a7952a0d01bfae8ac76beaaf697dc0f7..390012c107c1ce7a9a96dba51d37eba4e3addde5 100644 (file)
@@ -2296,24 +2296,28 @@ PHP_FUNCTION(array_slice)
        zval     *input,                /* Input array */
                        **entry;                /* An array entry */
        long     offset,                /* Offset to get elements from */
-                        length = 0;    /* How many elements to get */
+                        length = 0;
        zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */
        int              num_in,                /* Number of elements in the input array */
                         pos;                   /* Current position in the array */
+       zval    *z_length;      /* How many elements to get */
        zstr string_key;
        uint string_key_len;
        ulong num_key;
        HashPosition hpos;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lb", &input, &offset, &length, &preserve_keys) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|z/b", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
                return;
        }
 
        /* Get number of entries in the input hash */
        num_in = zend_hash_num_elements(Z_ARRVAL_P(input));
 
-       /* We want all entries from offset to the end if length is not passed or length is 0 */
-       if (length == 0) {
+       /* We want all entries from offset to the end if length is not passed or length is null */
+       if (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(z_length) != IS_NULL) {
+               convert_to_long(z_length);
+               length = Z_LVAL_P(z_length);
+       } else {
                length = num_in;
        }