ID:               36613
 Updated by:       [EMAIL PROTECTED]
 Reported By:      lists at zaunere dot com
-Status:           Open
+Status:           Verified
 Bug Type:         Feature/Change Request
 Operating System: Windows
 PHP Version:      5.1.2
 New Comment:

Workaround: array_slice($someArray, 1, count($someArray), true);
Patch: http://php.is/bugs/36613/array_slice.patch.txt

Index: array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.308.2.18
diff -u -r1.308.2.18 array.c
--- array.c     26 Feb 2006 10:49:50 -0000      1.308.2.18
+++ array.c     5 Mar 2006 02:20:28 -0000
@@ -2183,7 +2183,7 @@
           is not passed */
        convert_to_long_ex(offset);
        offset_val = Z_LVAL_PP(offset);
-       if (argc >= 3) {
+       if (argc == 3 || (argc == 4 && Z_TYPE_PP(length) != IS_NULL)) {
                convert_to_long_ex(length);
                length_val = Z_LVAL_PP(length);
        } else {



Previous Comments:
------------------------------------------------------------------------

[2006-03-04 21:27:47] lists at zaunere dot com

Description:
------------
The optional fourth parameter preserve_keys is only available if the
third parameter length is also supplied.  If the developer wishes to
set preserve_keys to TRUE, he must also supply the length of the array
he wishes to have returned, which may not be known.

There is no way to indicate that length should remain optional - like
passing NULL - while providing a value for preserve_keys.

Reproduce code:
---------------
$SomeArray = array('First','Middle','Last');

var_dump(array_slice($SomeArray,1,NULL,TRUE));

Expected result:
----------------
array(2) {
  [1]=>
  string(6) "Middle"
  [2]=>
  string(4) "Last"
}


Actual result:
--------------
array(0) {
}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36613&edit=1

Reply via email to