Skip to content

Commit fdc1330

Browse files
committed
Convert count_chars invalid mode error to ValueError
1 parent 2fcd454 commit fdc1330

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static const func_info_t func_infos[] = {
196196
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),
197197
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),
198198
F1("str_repeat", MAY_BE_NULL | MAY_BE_STRING),
199-
F1("count_chars", MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_LONG),
199+
F1("count_chars", MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_LONG),
200200
F1("chunk_split", MAY_BE_FALSE | MAY_BE_STRING),
201201
FN("trim", MAY_BE_STRING),
202202
FN("ltrim", MAY_BE_STRING),

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,7 +5359,7 @@ PHP_FUNCTION(str_repeat)
53595359
}
53605360
/* }}} */
53615361

5362-
/* {{{ proto array|string|false count_chars(string input [, int mode])
5362+
/* {{{ proto array|string count_chars(string input [, int mode])
53635363
Returns info about what characters are used in input */
53645364
PHP_FUNCTION(count_chars)
53655365
{
@@ -5379,8 +5379,8 @@ PHP_FUNCTION(count_chars)
53795379
ZEND_PARSE_PARAMETERS_END();
53805380

53815381
if (mymode < 0 || mymode > 4) {
5382-
php_error_docref(NULL, E_WARNING, "Unknown mode");
5383-
RETURN_FALSE;
5382+
zend_value_error("Unknown mode");
5383+
return;
53845384
}
53855385

53865386
buf = (const unsigned char *) ZSTR_VAL(input);

ext/standard/tests/strings/count_chars_basic.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ var_dump(count_chars($string, 2));
2020
var_dump(count_chars($string, 3));
2121
var_dump(bin2hex(count_chars($string, 4)));
2222

23+
try {
24+
count_chars($string, 5);
25+
} catch (ValueError $e) {
26+
echo $e->getMessage(), "\n";
27+
}
2328

2429
?>
2530
===DONE===
@@ -1571,4 +1576,5 @@ array(238) {
15711576
}
15721577
string(18) " Rabcdefghimnorstu"
15731578
string(476) "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051535455565758595a5b5c5d5e5f606a6b6c7071767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
1579+
Unknown mode
15741580
===DONE===

0 commit comments

Comments
 (0)