]> granicus.if.org Git - php/commitdiff
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:46:20 +0000 (11:46 +0000)
committerKalle Sommer Nielsen <kalle@php.net>
Tue, 3 Mar 2009 11:46:20 +0000 (11:46 +0000)
ext/standard/string.c
ext/standard/tests/strings/bug47546.phpt [new file with mode: 0644]

index 7806a8107b280a02b4a5da7ecef7b50665da3d2f..c0b37aae20f6f7d991f3e32ed21dcc0cacb41a1a 100644 (file)
@@ -1311,7 +1311,7 @@ PHP_FUNCTION(explode)
                } else {
                        add_index_stringl(return_value, 0, (char *)str, str_len, 1);
                }
-       } else if (limit < 0 && argc == 3) {
+       } else if (limit < -1 && argc == 3) {
                if ( str_type == IS_UNICODE ) {
                        php_u_explode_negative_limit((UChar *)delim, delim_len, (UChar *)str, str_len, return_value, limit);
                } else {
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
+)