The manual kind of skirts around it: "If length is given and is positive, then the sequence will have that many elements in it. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array ."

Meaning, basically, -1 is the same as omitted and the same as null?

No, that works as it says in the manual. -1 is one short of all elements. The only thing the manual doesn't say is what it means by 'omitted', so it's down to whether anyone's found 0 useful when it acts as it always has. If they haven't, we can move to long and break any existing code that uses something other than an integer, but at least we'll be giving a warning about it. If they have, we don't have any option but to stay with the zval and fix it to work as it did up until last month. Warnings in that case would be an added extra.

- Steph

ps Sane patches attached for both the long version and the zval version (with no warnings). The current test for array_slice behaviour will need fixing whatever the decision is. Please ignore everything on the associated bug report..

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Index: ext/standard/array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.308.2.21.2.37.2.11
diff -u -r1.308.2.21.2.37.2.11 array.c
--- ext/standard/array.c        5 Dec 2007 19:55:31 -0000       
1.308.2.21.2.37.2.11
+++ ext/standard/array.c        9 Dec 2007 23:07:13 -0000
@@ -2120,6 +2120,7 @@

        /* We want all entries from offset to the end if length is not passed 
or is null */
        if (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(length_param) != IS_NULL) {
+               convert_to_long(length_param);
                length = Z_LVAL_P(length_param);
        } else {
                length = num_in;
Index: ext/standard/array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.308.2.21.2.37.2.11
diff -u -r1.308.2.21.2.37.2.11 array.c
--- ext/standard/array.c        5 Dec 2007 19:55:31 -0000       
1.308.2.21.2.37.2.11
+++ ext/standard/array.c        10 Dec 2007 18:40:05 -0000
@@ -2101,17 +2101,16 @@
        zval     *input,                /* Input array */
                        **entry;                /* An array entry */
        long     offset,                /* Offset to get elements from */
-                        length;                /* How many elements to get */
+                        length = 0;    /* How many elements to get */
        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    *length_param;
        char *string_key;
        uint string_key_len;
        ulong num_key;
        HashPosition hpos;

-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset, 
&length_param, &preserve_keys) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lb", &input, &offset, 
&length, &preserve_keys) == FAILURE) {
                return;
        }

@@ -2119,9 +2118,7 @@
        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 (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(length_param) != IS_NULL) {
-               length = Z_LVAL_P(length_param);
-       } else {
+       if (length == IS_NULL) {
                length = num_in;
        }
        

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to