]> granicus.if.org Git - php/commitdiff
Fixed bug #41686 (Omitting length param in array_slice not possible).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 18 Jun 2007 16:53:09 +0000 (16:53 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 18 Jun 2007 16:53:09 +0000 (16:53 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug41686.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7282c5b8e8dd272c71299b94f0865bdc85738d3f..3656a345234be8b27c36e5cf392dc83c32337eb3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ PHP                                                                        NEWS
 - Fixed bug #41724 (libxml_get_last_error() - errors survice request scope).
   (thekid at php dot net, Ilia)
 - Fixed bug #41717 (imagepolygon does not respect thickness). (Pierre)
+- Fixed bug #41686 (Omitting length param in array_slice not possible).
+  (Ilia)
 - Fixed bug #41655 (open_basedir bypass via glob()). (Ilia)
 - Fixed bug #41640 (get_class_vars produces error on class constants).
   (Johannes)
index 1901630ef550ed34b25fb2a41ddf676018e95c43..b698ead1ee638a4e5a2c5be198628907a4736827 100644 (file)
@@ -2213,7 +2213,7 @@ PHP_FUNCTION(array_slice)
           is not passed */
        convert_to_long_ex(offset);
        offset_val = Z_LVAL_PP(offset);
-       if (argc >= 3) {
+       if (argc >= 3 && Z_TYPE_PP(length) != IS_NULL) {
                convert_to_long_ex(length);
                length_val = Z_LVAL_PP(length);
        } else {
diff --git a/ext/standard/tests/array/bug41686.phpt b/ext/standard/tests/array/bug41686.phpt
new file mode 100644 (file)
index 0000000..9f1384e
--- /dev/null
@@ -0,0 +1,56 @@
+--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
\ No newline at end of file