]> granicus.if.org Git - php/commitdiff
MFB52: Fixed bug #41686
authorJani Taskinen <jani@php.net>
Fri, 2 Nov 2007 10:50:33 +0000 (10:50 +0000)
committerJani Taskinen <jani@php.net>
Fri, 2 Nov 2007 10:50:33 +0000 (10:50 +0000)
ext/standard/array.c
ext/standard/tests/array/bug41686.phpt [new file with mode: 0644]

index f0423ccb9e3a90cfba6dfd4acfc99d306b488c1d..f72f8aed61704abb3f5da7cb14fd10a3f918f9b2 100644 (file)
@@ -2309,7 +2309,7 @@ PHP_FUNCTION(array_slice)
        ulong num_key;
        HashPosition hpos;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lb", &input,
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|l!b", &input,
                                                          &offset, &length, &preserve_keys) == FAILURE) {
                return;
        }
@@ -2317,8 +2317,8 @@ PHP_FUNCTION(array_slice)
        /* 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 */
-       if (ZEND_NUM_ARGS() < 3) {
+       /* We want all entries from offset to the end if length is not passed or length is null */
+       if (ZEND_NUM_ARGS() < 3 || length == NULL) {
                length = num_in;
        }
 
diff --git a/ext/standard/tests/array/bug41686.phpt b/ext/standard/tests/array/bug41686.phpt
new file mode 100644 (file)
index 0000000..74863f0
--- /dev/null
@@ -0,0 +1,94 @@
+--TEST--
+Bug #41686 (Omitting length param in array_slice not possible)
+--FILE--
+<?php
+$a = array(1,2,3);
+$b = array('a'=>1,'b'=>1,'c'=>2);
+
+var_dump(
+               array_slice($a, 1), 
+               array_slice($a, 1, 2, TRUE),
+               array_slice($a, 1, NULL, TRUE), 
+               array_slice($b, 1), 
+               array_slice($b, 1, 2, TRUE), 
+               array_slice($b, 1, NULL, TRUE)
+);
+
+echo "Done\n";
+?>
+--EXPECT--     
+array(2) {
+  [0]=>
+  int(2)
+  [1]=>
+  int(3)
+}
+array(2) {
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+array(2) {
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+array(2) {
+  ["b"]=>
+  int(1)
+  ["c"]=>
+  int(2)
+}
+array(2) {
+  ["b"]=>
+  int(1)
+  ["c"]=>
+  int(2)
+}
+array(2) {
+  ["b"]=>
+  int(1)
+  ["c"]=>
+  int(2)
+}
+Done
+--UEXPECT--
+array(2) {
+  [0]=>
+  int(2)
+  [1]=>
+  int(3)
+}
+array(2) {
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+array(2) {
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+array(2) {
+  [u"b"]=>
+  int(1)
+  [u"c"]=>
+  int(2)
+}
+array(2) {
+  [u"b"]=>
+  int(1)
+  [u"c"]=>
+  int(2)
+}
+array(2) {
+  [u"b"]=>
+  int(1)
+  [u"c"]=>
+  int(2)
+}
+Done