com php-src: Promote warnings to errors in str_word_count (): ext/standard/string.c ext/standard/tests/string s/str_word_count.phpt
ext/standard/tests/strings/str_ word_count1.phpt

From: Date: Thu, 22 Aug 2019 19:45:07 +0000
Subject: com php-src: Promote warnings to errors in str_word_count (): ext/standard/string.c ext/standard/tests/string s/str_word_count.phpt
ext/standard/tests/strings/str_ word_count1.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-107995@lists.php.net to get a copy of this message
Commit: fdff6cfd50521d654d8b10597bd7ae3c2c1eea84 Author: George Peter Banyard <girgias@php.net> Thu, 22 Aug 2019 12:18:12 +0200 Parents: 754d9f3da49c720d2945e6b2c95f652799681bf9 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fdff6cfd50521d654d8b10597bd7ae3c2c1eea84 Log: Promote warnings to errors in str_word_count() Changed paths: M ext/standard/string.c M ext/standard/tests/strings/str_word_count.phpt M ext/standard/tests/strings/str_word_count1.phpt Diff: diff --git a/ext/standard/string.c b/ext/standard/string.c index a1b6193..e756a99 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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) { diff --git a/ext/standard/tests/strings/str_word_count.phpt b/ext/standard/tests/strings/str_word_count.phpt index e8fa12a..375f26d 100644 --- a/ext/standard/tests/strings/str_word_count.phpt +++ b/ext/standard/tests/strings/str_word_count.phpt @@ -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 diff --git a/ext/standard/tests/strings/str_word_count1.phpt b/ext/standard/tests/strings/str_word_count1.phpt index e942a17..1865269 100644 --- a/ext/standard/tests/strings/str_word_count1.phpt +++ b/ext/standard/tests/strings/str_word_count1.phpt @@ -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

« previous php.cvs (#107995) next »