From: Felipe Pena Date: Tue, 12 Feb 2008 01:49:42 +0000 (+0000) Subject: MFB: array_slice() - Fixed behavior when NULL is given in third parameter (BC) X-Git-Tag: RELEASE_2_0_0a1~515 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd18a414a0c79440837e330bf564254cb367bdf2;p=php MFB: array_slice() - Fixed behavior when NULL is given in third parameter (BC) --- diff --git a/ext/standard/array.c b/ext/standard/array.c index abea380702..69a552d8b5 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2294,6 +2294,7 @@ PHP_FUNCTION(array_splice) PHP_FUNCTION(array_slice) { zval *input, /* Input array */ + **z_length, /* How many elements to get */ **entry; /* An array entry */ long offset, /* Offset to get elements from */ length = 0; @@ -2305,7 +2306,7 @@ PHP_FUNCTION(array_slice) 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|Zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) { return; } @@ -2313,8 +2314,11 @@ PHP_FUNCTION(array_slice) 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 null */ - if (length == 0) { + if (ZEND_NUM_ARGS() < 3 || Z_TYPE_PP(z_length) == IS_NULL) { length = num_in; + } else { + convert_to_long_ex(z_length); + length = Z_LVAL_PP(z_length); } /* Initialize returned array */