File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -5882,9 +5882,14 @@ PHP_FUNCTION(str_split)
5882
5882
RETURN_THROWS ();
5883
5883
}
5884
5884
5885
- if (0 == ZSTR_LEN (str ) || (size_t )split_length >= ZSTR_LEN (str )) {
5886
- array_init_size (return_value , 1 );
5887
- add_next_index_stringl (return_value , ZSTR_VAL (str ), ZSTR_LEN (str ));
5885
+ if ((size_t )split_length >= ZSTR_LEN (str )) {
5886
+ if (0 == ZSTR_LEN (str )) {
5887
+ array_init_size (return_value , 0 );
5888
+ } else {
5889
+ array_init_size (return_value , 1 );
5890
+ add_next_index_stringl (return_value , ZSTR_VAL (str ), ZSTR_LEN (str ));
5891
+ }
5892
+
5888
5893
return ;
5889
5894
}
5890
5895
Original file line number Diff line number Diff line change @@ -16,7 +16,11 @@ var_dump( str_split($str,$split_length) );
16
16
echo "-- With split_length as default argument -- \n" ;
17
17
var_dump ( str_split ($ str ) );
18
18
19
- echo "Done "
19
+ echo "-- Empty string must always return empty array -- \n" ;
20
+ var_dump ( str_split ('' ) );
21
+ var_dump ( str_split ('' , 1 ) );
22
+ var_dump ( str_split ('' , 100 ) );
23
+
20
24
?>
21
25
--EXPECT--
22
26
*** Testing str_split() : basic functionality ***
@@ -80,4 +84,10 @@ array(22) {
80
84
[21]=>
81
85
string(1) "e"
82
86
}
83
- Done
87
+ -- Empty string must always return empty array --
88
+ array(0) {
89
+ }
90
+ array(0) {
91
+ }
92
+ array(0) {
93
+ }
You can’t perform that action at this time.
0 commit comments