Skip to content

Commit 698491d

Browse files
committed
Promote warnings to errors in str_split()
1 parent c0554fd commit 698491d

File tree

5 files changed

+51
-57
lines changed

5 files changed

+51
-57
lines changed

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6058,7 +6058,7 @@ PHP_FUNCTION(money_format)
60586058
/* }}} */
60596059
#endif
60606060

6061-
/* {{{ proto array|false str_split(string str [, int split_length])
6061+
/* {{{ proto array str_split(string str [, int split_length])
60626062
Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */
60636063
PHP_FUNCTION(str_split)
60646064
{
@@ -6074,8 +6074,8 @@ PHP_FUNCTION(str_split)
60746074
ZEND_PARSE_PARAMETERS_END();
60756075

60766076
if (split_length <= 0) {
6077-
php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero");
6078-
RETURN_FALSE;
6077+
zend_throw_error(NULL, "The length of each segment must be greater than zero");
6078+
return;
60796079
}
60806080

60816081

ext/standard/tests/strings/str_split_variation6.phpt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
1818
* passing different integer values for 'split_length' argument to str_split()
1919
*/
2020

21-
echo "*** Testing str_split() : different intger values for 'split_length' ***\n";
21+
echo "*** Testing str_split() : different integer values for 'split_length' ***\n";
2222
//Initialise variables
2323
$str = 'This is a string with 123 & escape char \t';
2424

@@ -35,17 +35,20 @@ $values = array (
3535

3636
//loop through each element of $values for 'split_length'
3737
for($count = 0; $count < count($values); $count++) {
38-
echo "-- Iteration ".($count + 1)." --\n";
39-
var_dump( str_split($str, $values[$count]) );
38+
echo "-- Iteration ".($count + 1)." --\n";
39+
40+
try {
41+
var_dump( str_split($str, $values[$count]) );
42+
} catch (\Error $e) {
43+
echo $e->getMessage() . "\n";
44+
}
4045
}
4146
echo "Done"
4247
?>
43-
--EXPECTF--
44-
*** Testing str_split() : different intger values for 'split_length' ***
48+
--EXPECT--
49+
*** Testing str_split() : different integer values for 'split_length' ***
4550
-- Iteration 1 --
46-
47-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
48-
bool(false)
51+
The length of each segment must be greater than zero
4952
-- Iteration 2 --
5053
array(42) {
5154
[0]=>
@@ -134,9 +137,7 @@ array(42) {
134137
string(1) "t"
135138
}
136139
-- Iteration 3 --
137-
138-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
139-
bool(false)
140+
The length of each segment must be greater than zero
140141
-- Iteration 4 --
141142
array(1) {
142143
[0]=>
@@ -155,7 +156,5 @@ array(1) {
155156
string(42) "This is a string with 123 & escape char \t"
156157
}
157158
-- Iteration 7 --
158-
159-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
160-
bool(false)
159+
The length of each segment must be greater than zero
161160
Done

ext/standard/tests/strings/str_split_variation6_64bit.phpt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ $values = array (
3636

3737
//loop through each element of $values for 'split_length'
3838
for($count = 0; $count < count($values); $count++) {
39-
echo "-- Iteration ".($count + 1)." --\n";
40-
var_dump( str_split($str, $values[$count]) );
39+
echo "-- Iteration ".($count + 1)." --\n";
40+
try {
41+
var_dump( str_split($str, $values[$count]) );
42+
} catch (\Error $e) {
43+
echo $e->getMessage() . "\n";
44+
}
4145
}
4246
echo "Done"
4347
?>
44-
--EXPECTF--
48+
--EXPECT--
4549
*** Testing str_split() : different intger values for 'split_length' ***
4650
-- Iteration 1 --
47-
48-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
49-
bool(false)
51+
The length of each segment must be greater than zero
5052
-- Iteration 2 --
5153
array(42) {
5254
[0]=>
@@ -135,9 +137,7 @@ array(42) {
135137
string(1) "t"
136138
}
137139
-- Iteration 3 --
138-
139-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
140-
bool(false)
140+
The length of each segment must be greater than zero
141141
-- Iteration 4 --
142142
array(1) {
143143
[0]=>
@@ -161,7 +161,5 @@ array(1) {
161161
string(42) "This is a string with 123 & escape char \t"
162162
}
163163
-- Iteration 8 --
164-
165-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
166-
bool(false)
164+
The length of each segment must be greater than zero
167165
Done

ext/standard/tests/strings/str_split_variation7.phpt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
1818
* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
1919
*/
2020

21-
echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n";
21+
echo "*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***\n";
2222
//Initialise variables
2323
$str = <<<EOT
2424
string with 123,escape char \t.
@@ -37,17 +37,20 @@ $values = array (
3737

3838
//loop through each element of $values for 'split_length'
3939
for($count = 0; $count < count($values); $count++) {
40-
echo "-- Iteration ".($count + 1)." --\n";
41-
var_dump( str_split($str, $values[$count]) );
40+
echo "-- Iteration ".($count + 1)." --\n";
41+
42+
try {
43+
var_dump( str_split($str, $values[$count]) );
44+
} catch (\Error $e) {
45+
echo $e->getMessage() . "\n";
46+
}
4247
}
4348
echo "Done"
4449
?>
45-
--EXPECTF--
46-
*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
50+
--EXPECT--
51+
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
4752
-- Iteration 1 --
48-
49-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
50-
bool(false)
53+
The length of each segment must be greater than zero
5154
-- Iteration 2 --
5255
array(30) {
5356
[0]=>
@@ -112,9 +115,7 @@ array(30) {
112115
string(1) "."
113116
}
114117
-- Iteration 3 --
115-
116-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
117-
bool(false)
118+
The length of each segment must be greater than zero
118119
-- Iteration 4 --
119120
array(1) {
120121
[0]=>
@@ -133,7 +134,5 @@ array(1) {
133134
string(30) "string with 123,escape char ."
134135
}
135136
-- Iteration 7 --
136-
137-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
138-
bool(false)
137+
The length of each segment must be greater than zero
139138
Done

ext/standard/tests/strings/str_split_variation7_64bit.phpt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
1818
* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
1919
*/
2020

21-
echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n";
21+
echo "*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***\n";
2222
//Initialise variables
2323
$str = <<<EOT
2424
string with 123,escape char \t.
@@ -38,17 +38,19 @@ $values = array (
3838

3939
//loop through each element of $values for 'split_length'
4040
for($count = 0; $count < count($values); $count++) {
41-
echo "-- Iteration ".($count + 1)." --\n";
42-
var_dump( str_split($str, $values[$count]) );
41+
echo "-- Iteration ".($count + 1)." --\n";
42+
try {
43+
var_dump( str_split($str, $values[$count]) );
44+
} catch (\Error $e) {
45+
echo $e->getMessage() . "\n";
46+
}
4347
}
4448
echo "Done"
4549
?>
46-
--EXPECTF--
47-
*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
50+
--EXPECT--
51+
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
4852
-- Iteration 1 --
49-
50-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
51-
bool(false)
53+
The length of each segment must be greater than zero
5254
-- Iteration 2 --
5355
array(30) {
5456
[0]=>
@@ -113,9 +115,7 @@ array(30) {
113115
string(1) "."
114116
}
115117
-- Iteration 3 --
116-
117-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
118-
bool(false)
118+
The length of each segment must be greater than zero
119119
-- Iteration 4 --
120120
array(1) {
121121
[0]=>
@@ -139,7 +139,5 @@ array(1) {
139139
string(30) "string with 123,escape char ."
140140
}
141141
-- Iteration 8 --
142-
143-
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
144-
bool(false)
142+
The length of each segment must be greater than zero
145143
Done

0 commit comments

Comments
 (0)