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

index 1f60a0324ffcb09b185dccc41b6f6697f7a974cb..ce9f7c2a240153ed175f9fa9c7c6bbea599f2b23 100644 (file)
@@ -1294,10 +1294,12 @@ PHP_FUNCTION(explode)
        array_init(return_value);
 
        if ( str_len == 0 ) {
-               if ( str_type == IS_UNICODE ) {
-                       add_next_index_unicodel(return_value, USTR_MAKE(""), sizeof("")-1, 0);
-               } else {
-                       add_next_index_stringl(return_value, "", sizeof("")-1, 1);
+               if (limit >= 0 || argc == 2) {
+                       if ( str_type == IS_UNICODE ) {
+                               add_next_index_unicodel(return_value, USTR_MAKE(""), sizeof("")-1, 0);
+                       } else {
+                               add_next_index_stringl(return_value, "", sizeof("")-1, 1);
+                       }
                }
                return;
        }
index 44f5846f053ed5129a54be43bf46eca0abe52ab8..2ed242a247e0901ad780a6f4aee9fc30a16a3ce5 100644 (file)
@@ -18,6 +18,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)));
@@ -64,6 +65,8 @@ array(1) {
   [0]=>
   unicode(11) "otherstring"
 }
+array(0) {
+}
 array(7) {
   [0]=>
   unicode(0) ""