1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00

Promote warnings to errors in str_word_count()

This commit is contained in:
George Peter Banyard
2019-08-22 12:18:12 +02:00
parent 754d9f3da4
commit fdff6cfd50
3 changed files with 57 additions and 35 deletions
+4 -4
View File
@@ -5916,13 +5916,13 @@ PHP_FUNCTION(str_shuffle)
}
/* }}} */
/* {{{ proto mixed str_word_count(string str, [int format [, string charlist]])
/* {{{ proto array|int str_word_count(string str, [int format [, string charlist]])
Counts the number of words inside a string. If format of 1 is specified,
then the function will return an array containing all the words
found inside the string. If format of 2 is specified, then the function
will return an associated array where the position of the word is the key
and the word itself is the value.
For the purpose of this function, 'word' is defined as a locale dependent
string containing alphabetic characters, which also may contain, but not start
with "'" and "-" characters.
@@ -5957,8 +5957,8 @@ PHP_FUNCTION(str_word_count)
/* nothing to be done */
break;
default:
php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type);
RETURN_FALSE;
zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type);
return;
}
if (char_list) {
+34 -20
View File
@@ -2,17 +2,37 @@
str_word_count()
--FILE--
<?php
error_reporting(E_ALL);
$str = "Hello friend, you're
looking good today!";
$b =& $str;
var_dump(str_word_count($str, 1));
var_dump(str_word_count($str, 2));
var_dump(str_word_count($str));
var_dump(str_word_count($str, 3));
var_dump(str_word_count($str, 123));
var_dump(str_word_count($str, -1));
var_dump(str_word_count($str, 999999999));
try {
var_dump(str_word_count($str, 3));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, 123));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, -1));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, 999999999));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
var_dump($str);
$str2 = "F0o B4r 1s bar foo";
@@ -34,9 +54,10 @@ var_dump(str_word_count("'foo'", 2, "'"));
var_dump(str_word_count("-foo-", 2));
var_dump(str_word_count("-foo-", 2, "-"));
echo "Done\n";
?>
--EXPECTF--
DONE
--EXPECT--
array(6) {
[0]=>
string(5) "Hello"
@@ -66,18 +87,10 @@ array(6) {
string(5) "today"
}
int(6)
Warning: str_word_count(): Invalid format value 3 in %s on line %d
bool(false)
Warning: str_word_count(): Invalid format value 123 in %s on line %d
bool(false)
Warning: str_word_count(): Invalid format value -1 in %s on line %d
bool(false)
Warning: str_word_count(): Invalid format value 999999999 in %s on line %d
bool(false)
Invalid format value 3
Invalid format value 123
Invalid format value -1
Invalid format value 999999999
string(55) "Hello friend, you're
looking good today!"
int(5)
@@ -214,4 +227,5 @@ array(1) {
[0]=>
string(5) "-foo-"
}
Done
DONE
+19 -11
View File
@@ -4,23 +4,31 @@ str_word_count() and invalid arguments
<?php
var_dump(str_word_count(""));
var_dump(str_word_count("", -1));
var_dump(str_word_count("", -1, $a));
var_dump($a);
echo "Done\n";
try {
var_dump(str_word_count("", -1));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count("", -1, $a));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
var_dump($a);
?>
DONE
--EXPECTF--
int(0)
Warning: str_word_count(): Invalid format value -1 in %s on line %d
bool(false)
Invalid format value -1
Notice: Undefined variable: a in %s on line %d
Warning: str_word_count(): Invalid format value -1 in %s on line %d
bool(false)
Invalid format value -1
Notice: Undefined variable: a in %s on line %d
NULL
Done
DONE