]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #47546 (Default value for limit parameter in explode is 0, not -1)
authorKalle Sommer Nielsen <kalle@php.net>
Tue, 3 Mar 2009 11:47:31 +0000 (11:47 +0000)
committerKalle Sommer Nielsen <kalle@php.net>
Tue, 3 Mar 2009 11:47:31 +0000 (11:47 +0000)
ext/standard/string.c
ext/standard/tests/strings/bug47546.phpt [new file with mode: 0644]

index ca13c3960860097d37f794a420de77c893d08ddc..f1927aa127dbbff696b07df66857ff2237a19596 100644 (file)
@@ -1027,7 +1027,7 @@ PHP_FUNCTION(explode)
 
        if (limit == 0 || limit == 1) {
                add_index_stringl(return_value, 0, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1);
-       } else if (limit < 0 && argc == 3) {
+       } else if (limit < -1 && argc == 3) {
                php_explode_negative_limit(*delim, *str, return_value, limit);
        } else {
                php_explode(*delim, *str, return_value, limit);
diff --git a/ext/standard/tests/strings/bug47546.phpt b/ext/standard/tests/strings/bug47546.phpt
new file mode 100644 (file)
index 0000000..f04f9be
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #47546 (Default value for limit parameter in explode is 0, not -1)
+--FILE--
+<?php
+$str = 'one|two|three|four';
+
+print_r(explode('|', $str));
+print_r(explode('|', $str, -1));
+?>
+--EXPECT--
+Array
+(
+    [0] => one
+    [1] => two
+    [2] => three
+    [3] => four
+)
+Array
+(
+    [0] => one
+    [1] => two
+    [2] => three
+    [3] => four
+)