com php-src: Convert count_chars invalid mode error t o ValueError: ext/opcache/Optimizer/zend_func_info. c ext/standard/string.c
ext/standard/tests/strings/count _chars_basic.phpt
| From: | Nikita Popov | Date: | Mon, 07 Oct 2019 09:10:05 +0000 |
| Subject: | com php-src: Convert count_chars invalid mode error t o ValueError: ext/opcache/Optimizer/zend_func_info. c ext/standard/string.c ext/standard/tests/strings/count _chars_basic.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108757@lists.php.net to get a copy of this message | ||
Commit: fdc133063d30385866b0eb84e8592aad2f94834e
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 7 Oct 2019 11:10:05 +0200
Parents: 2fcd454480843c814f2edc888e9ff176ca4c92f0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fdc133063d30385866b0eb84e8592aad2f94834e
Log:
Convert count_chars invalid mode error to ValueError
Changed paths:
M ext/opcache/Optimizer/zend_func_info.c
M ext/standard/string.c
M ext/standard/tests/strings/count_chars_basic.phpt
Diff:
diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c
index 179a83084d2..d21e9a48b46 100644
--- a/ext/opcache/Optimizer/zend_func_info.c
+++ b/ext/opcache/Optimizer/zend_func_info.c
@@ -196,7 +196,7 @@ static const func_info_t func_infos[] = {
FN("str_replace", MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY |
MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY | MAY_BE_ARRAY_OF_OBJECT),
FN("str_ireplace", MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY |
MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY | MAY_BE_ARRAY_OF_OBJECT),
F1("str_repeat", MAY_BE_NULL | MAY_BE_STRING),
- F1("count_chars", MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY |
MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_LONG),
+ F1("count_chars", MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG
| MAY_BE_ARRAY_OF_LONG),
F1("chunk_split", MAY_BE_FALSE | MAY_BE_STRING),
FN("trim", MAY_BE_STRING),
FN("ltrim", MAY_BE_STRING),
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 7a79ace570d..81f1cebb527 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -5359,7 +5359,7 @@ PHP_FUNCTION(str_repeat)
}
/* }}} */
-/* {{{ proto array|string|false count_chars(string input [, int mode])
+/* {{{ proto array|string count_chars(string input [, int mode])
Returns info about what characters are used in input */
PHP_FUNCTION(count_chars)
{
@@ -5379,8 +5379,8 @@ PHP_FUNCTION(count_chars)
ZEND_PARSE_PARAMETERS_END();
if (mymode < 0 || mymode > 4) {
- php_error_docref(NULL, E_WARNING, "Unknown mode");
- RETURN_FALSE;
+ zend_value_error("Unknown mode");
+ return;
}
buf = (const unsigned char *) ZSTR_VAL(input);
diff --git a/ext/standard/tests/strings/count_chars_basic.phpt
b/ext/standard/tests/strings/count_chars_basic.phpt
index c39889be156..ddf7adac878 100644
--- a/ext/standard/tests/strings/count_chars_basic.phpt
+++ b/ext/standard/tests/strings/count_chars_basic.phpt
@@ -20,6 +20,11 @@ var_dump(count_chars($string, 2));
var_dump(count_chars($string, 3));
var_dump(bin2hex(count_chars($string, 4)));
+try {
+ count_chars($string, 5);
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
===DONE===
@@ -1571,4 +1576,5 @@ array(238) {
}
string(18) " Rabcdefghimnorstu"
string(476)
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051535455565758595a5b5c5d5e5f606a6b6c7071767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
+Unknown mode
===DONE===