From aba0ee71b224ab11a4b940f06dd1146eddbd41a3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 22 Sep 2020 11:42:50 +0200 Subject: [PATCH] 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. --- ext/opcache/Optimizer/zend_func_info.c | 2 +- ext/standard/basic_functions.stub.php | 2 +- ext/standard/basic_functions_arginfo.h | 14 ++++++-------- ext/standard/soundex.c | 4 ---- ext/standard/tests/strings/soundex.phpt | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 043a660d6c..10a90aff2d 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -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), diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index bd185d5382..da890a5735 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -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 */ diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 64f35950a4..82a88ddee4 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -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) diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c index 5342139f98..db57c1ef69 100644 --- a/ext/standard/soundex.c +++ b/ext/standard/soundex.c @@ -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++) { diff --git a/ext/standard/tests/strings/soundex.phpt b/ext/standard/tests/strings/soundex.phpt index c4acc2ff68..95d0b76085 100644 --- a/ext/standard/tests/strings/soundex.phpt +++ b/ext/standard/tests/strings/soundex.phpt @@ -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" -- 2.40.0