]> granicus.if.org Git - php/commitdiff
Don't return false for empty string in soundex()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 09:42:50 +0000 (11:42 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 09:44:35 +0000 (11:44 +0200)
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
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/soundex.c
ext/standard/tests/strings/soundex.phpt

index 043a660d6c406984507ec06bcce235c0c4ebacff..10a90aff2dc85c6a7e36bb349f0a28426aaa936b 100644 (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),
index bd185d53820409a6646ae561695c0da211ea174d..da890a57356094dd8e978d954be84b11775dc377 100755 (executable)
@@ -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 */
 
index 64f35950a4c5743e860bf9c6688eb323611cb210..82a88ddee4c06c65e0a8c55493f91b84ea38768b 100644 (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)
index 5342139f98d0001c1af756ff8f4fff074a364d87..db57c1ef6991afcd427c82cfa98e61562500f853 100644 (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++) {
index c4acc2ff6842df1415d6f8dec978cabf483252d9..95d0b76085e7901ca0b968b7329c77e35d2dcf9f 100644 (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"