Skip to content

Promote warnings to errors in str_split() #4595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -6058,7 +6058,7 @@ PHP_FUNCTION(money_format)
/* }}} */
#endif

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

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


Expand Down
27 changes: 13 additions & 14 deletions ext/standard/tests/strings/str_split_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
* passing different integer values for 'split_length' argument to str_split()
*/

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

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

//loop through each element of $values for 'split_length'
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
var_dump( str_split($str, $values[$count]) );
echo "-- Iteration ".($count + 1)." --\n";

try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECTF--
*** Testing str_split() : different intger values for 'split_length' ***
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' ***
-- Iteration 1 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 2 --
array(42) {
[0]=>
Expand Down Expand Up @@ -134,9 +137,7 @@ array(42) {
string(1) "t"
}
-- Iteration 3 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 4 --
array(1) {
[0]=>
Expand All @@ -155,7 +156,5 @@ array(1) {
string(42) "This is a string with 123 & escape char \t"
}
-- Iteration 7 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
Done
22 changes: 10 additions & 12 deletions ext/standard/tests/strings/str_split_variation6_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ $values = array (

//loop through each element of $values for 'split_length'
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
var_dump( str_split($str, $values[$count]) );
echo "-- Iteration ".($count + 1)." --\n";
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECTF--
--EXPECT--
*** Testing str_split() : different intger values for 'split_length' ***
-- Iteration 1 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 2 --
array(42) {
[0]=>
Expand Down Expand Up @@ -135,9 +137,7 @@ array(42) {
string(1) "t"
}
-- Iteration 3 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 4 --
array(1) {
[0]=>
Expand All @@ -161,7 +161,5 @@ array(1) {
string(42) "This is a string with 123 & escape char \t"
}
-- Iteration 8 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
Done
27 changes: 13 additions & 14 deletions ext/standard/tests/strings/str_split_variation7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
*/

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

//loop through each element of $values for 'split_length'
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
var_dump( str_split($str, $values[$count]) );
echo "-- Iteration ".($count + 1)." --\n";

try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECTF--
*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
-- Iteration 1 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 2 --
array(30) {
[0]=>
Expand Down Expand Up @@ -112,9 +115,7 @@ array(30) {
string(1) "."
}
-- Iteration 3 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 4 --
array(1) {
[0]=>
Expand All @@ -133,7 +134,5 @@ array(1) {
string(30) "string with 123,escape char ."
}
-- Iteration 7 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
Done
26 changes: 12 additions & 14 deletions ext/standard/tests/strings/str_split_variation7_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
*/

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

//loop through each element of $values for 'split_length'
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
var_dump( str_split($str, $values[$count]) );
echo "-- Iteration ".($count + 1)." --\n";
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECTF--
*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
-- Iteration 1 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 2 --
array(30) {
[0]=>
Expand Down Expand Up @@ -113,9 +115,7 @@ array(30) {
string(1) "."
}
-- Iteration 3 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
-- Iteration 4 --
array(1) {
[0]=>
Expand All @@ -139,7 +139,5 @@ array(1) {
string(30) "string with 123,escape char ."
}
-- Iteration 8 --

Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
The length of each segment must be greater than zero
Done