summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2019-08-22 11:33:48 +0200
committerGeorge Peter Banyard <girgias@php.net>2019-08-22 19:33:37 +0200
commit698491d98a8d34e1d531a36f5dba30fc424b826f (patch)
tree4a24afe9223f9fdd43965e2ca10d002532bd7204 /ext
parentc0554fdec5a73f34472fdcf082179ae4895c903d (diff)
downloadphp-git-698491d98a8d34e1d531a36f5dba30fc424b826f.tar.gz
Promote warnings to errors in str_split()
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/string.c6
-rw-r--r--ext/standard/tests/strings/str_split_variation6.phpt27
-rw-r--r--ext/standard/tests/strings/str_split_variation6_64bit.phpt22
-rw-r--r--ext/standard/tests/strings/str_split_variation7.phpt27
-rw-r--r--ext/standard/tests/strings/str_split_variation7_64bit.phpt26
5 files changed, 51 insertions, 57 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e8a8fed1ac..c98ee49d49 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 1aea668026..111eb11858 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 583c7db3cf..e6893e9263 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 1a2471a20a..a810dd7ecb 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 = <<<EOT
string with 123,escape char \t.
@@ -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]=>
@@ -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 bff61adb30..1a1980028a 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 = <<<EOT
string with 123,escape char \t.
@@ -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]=>
@@ -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