]> granicus.if.org Git - php/commitdiff
array_slice() - Fixed behavior when NULL is given in third parameter (BC)
authorFelipe Pena <felipe@php.net>
Tue, 12 Feb 2008 01:31:12 +0000 (01:31 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 12 Feb 2008 01:31:12 +0000 (01:31 +0000)
ext/standard/array.c

index 8328a931e85bcf7661701b493a66ffb4be14c658..a8cea5483ac9c9ddabacd5f4cf6ffff44331c0d0 100644 (file)
@@ -2107,9 +2107,10 @@ 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;    /* 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 */
@@ -2118,7 +2119,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;
        }
 
@@ -2126,8 +2127,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 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 */