Don't return false for empty string in soundex()

Return "0000" instead of false to have a consistent return type.
"0000" is already a possible return value if the string doesn't
contain any letters, such as with soundex(" "). We can treat the
case of soundex("") exactly the same.
This commit is contained in:
Nikita Popov 2020-09-22 11:42:50 +02:00
parent f26d855e29
commit aba0ee71b2
5 changed files with 9 additions and 15 deletions

View file

@ -175,7 +175,7 @@ static const func_info_t func_infos[] = {
#if HAVE_NL_LANGINFO
F1("nl_langinfo", MAY_BE_FALSE | MAY_BE_STRING),
#endif
F1("soundex", MAY_BE_FALSE | MAY_BE_STRING),
F1("soundex", MAY_BE_STRING),
F1("chr", MAY_BE_STRING),
F1("str_getcsv", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING),
F1("strchr", MAY_BE_FALSE | MAY_BE_STRING),

View file

@ -1199,7 +1199,7 @@ function random_int(int $min, int $max): int {}
/* soundex.c */
function soundex(string $string): string|false {}
function soundex(string $string): string {}
/* streamsfuncs.c */

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: d840ea5a32c8414bdc29e21635e7a36ee7c202e1 */
* Stub hash: 56fb3ef4c53a1ed7abf6a115567bca47e1a14cda */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@ -1842,7 +1842,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_random_int, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, max, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_soundex, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_soundex, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_END_ARG_INFO()
@ -2121,15 +2121,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_url, 0, 0, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, component, IS_LONG, 0, "-1")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_urlencode, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_urlencode arginfo_soundex
#define arginfo_urldecode arginfo_urlencode
#define arginfo_urldecode arginfo_soundex
#define arginfo_rawurlencode arginfo_urlencode
#define arginfo_rawurlencode arginfo_soundex
#define arginfo_rawurldecode arginfo_urlencode
#define arginfo_rawurldecode arginfo_soundex
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_headers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, url, IS_STRING, 0)

View file

@ -60,10 +60,6 @@ PHP_FUNCTION(soundex)
Z_PARAM_STRING(str, str_len)
ZEND_PARSE_PARAMETERS_END();
if (str_len == 0) {
RETURN_FALSE;
}
/* build soundex string */
last = -1;
for (i = 0, _small = 0; i < str_len && _small < 4; i++) {

View file

@ -31,7 +31,7 @@ foreach ($array as $str) {
echo "Done\n";
?>
--EXPECT--
bool(false)
string(4) "0000"
string(4) "0000"
string(4) "F650"
string(4) "T300"