From e363bf5aae625108c83b43a1a28f689383a41e9c Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 22 Aug 2019 11:33:48 +0200 Subject: [PATCH] Promote warnings to errors in str_split() --- ext/standard/string.c | 6 ++--- .../tests/strings/str_split_variation6.phpt | 27 +++++++++---------- .../strings/str_split_variation6_64bit.phpt | 22 +++++++-------- .../tests/strings/str_split_variation7.phpt | 27 +++++++++---------- .../strings/str_split_variation7_64bit.phpt | 26 +++++++++--------- 5 files changed, 51 insertions(+), 57 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index c2f29baec7732..3a8c1e0ea7e67 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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) { @@ -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; } diff --git a/ext/standard/tests/strings/str_split_variation6.phpt b/ext/standard/tests/strings/str_split_variation6.phpt index 1aea668026310..111eb11858aa4 100644 --- a/ext/standard/tests/strings/str_split_variation6.phpt +++ b/ext/standard/tests/strings/str_split_variation6.phpt @@ -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'; @@ -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]=> @@ -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]=> @@ -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 diff --git a/ext/standard/tests/strings/str_split_variation6_64bit.phpt b/ext/standard/tests/strings/str_split_variation6_64bit.phpt index 583c7db3cf65f..e6893e9263ea5 100644 --- a/ext/standard/tests/strings/str_split_variation6_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation6_64bit.phpt @@ -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]=> @@ -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]=> @@ -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 diff --git a/ext/standard/tests/strings/str_split_variation7.phpt b/ext/standard/tests/strings/str_split_variation7.phpt index 1a2471a20a88b..a810dd7ecb4d0 100644 --- a/ext/standard/tests/strings/str_split_variation7.phpt +++ b/ext/standard/tests/strings/str_split_variation7.phpt @@ -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 = <<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]=> @@ -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]=> @@ -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 diff --git a/ext/standard/tests/strings/str_split_variation7_64bit.phpt b/ext/standard/tests/strings/str_split_variation7_64bit.phpt index bff61adb30244..1a1980028a214 100644 --- a/ext/standard/tests/strings/str_split_variation7_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation7_64bit.phpt @@ -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 = <<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]=> @@ -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]=> @@ -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