]> granicus.if.org Git - php/commitdiff
MFH: fix explode behavior to respect negative limit when string is empty.
authorBrian Shire <shire@php.net>
Sat, 27 Dec 2008 05:15:51 +0000 (05:15 +0000)
committerBrian Shire <shire@php.net>
Sat, 27 Dec 2008 05:15:51 +0000 (05:15 +0000)
ext/standard/string.c
ext/standard/tests/strings/explode.phpt

index d3a6fdffd88584322471971504dcba2e9ca030f4..8e85045f666a0f05720caf31e8829d791f93f7fa 100644 (file)
@@ -1018,7 +1018,9 @@ PHP_FUNCTION(explode)
        array_init(return_value);
 
        if (! Z_STRLEN_PP(str)) {
-               add_next_index_stringl(return_value, "", sizeof("") - 1, 1);
+               if (limit >= 0 || argc == 2) {
+                       add_next_index_stringl(return_value, "", sizeof("") - 1, 1);
+               } 
                return;
        }
 
index 6d54b6609042e94fdf1658ae42906256e4abab8b..1047fb7856295ec28f399c23f8397edf19cd5e23 100644 (file)
@@ -17,6 +17,7 @@ var_dump(@explode("a", NULL));
 var_dump(@explode(NULL, a));
 var_dump(@explode("abc", "acb"));
 var_dump(@explode("somestring", "otherstring"));
+var_dump(@explode("somestring", "otherstring", -1));
 var_dump(@explode("a", "aaaaaa"));
 var_dump(@explode("==", str_repeat("-=".ord(0)."=-", 10)));
 var_dump(@explode("=", str_repeat("-=".ord(0)."=-", 10)));
@@ -63,6 +64,8 @@ array(1) {
   [0]=>
   string(11) "otherstring"
 }
+array(0) {
+}
 array(7) {
   [0]=>
   string(0) ""