Skip to content

Commit aba0ee7

Browse files
committed
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.
1 parent f26d855 commit aba0ee7

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static const func_info_t func_infos[] = {
175175
#if HAVE_NL_LANGINFO
176176
F1("nl_langinfo", MAY_BE_FALSE | MAY_BE_STRING),
177177
#endif
178-
F1("soundex", MAY_BE_FALSE | MAY_BE_STRING),
178+
F1("soundex", MAY_BE_STRING),
179179
F1("chr", MAY_BE_STRING),
180180
F1("str_getcsv", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING),
181181
F1("strchr", MAY_BE_FALSE | MAY_BE_STRING),

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ function random_int(int $min, int $max): int {}
11991199

12001200
/* soundex.c */
12011201

1202-
function soundex(string $string): string|false {}
1202+
function soundex(string $string): string {}
12031203

12041204
/* streamsfuncs.c */
12051205

ext/standard/basic_functions_arginfo.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d840ea5a32c8414bdc29e21635e7a36ee7c202e1 */
2+
* Stub hash: 56fb3ef4c53a1ed7abf6a115567bca47e1a14cda */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
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)
18421842
ZEND_ARG_TYPE_INFO(0, max, IS_LONG, 0)
18431843
ZEND_END_ARG_INFO()
18441844

1845-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_soundex, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
1845+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_soundex, 0, 1, IS_STRING, 0)
18461846
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
18471847
ZEND_END_ARG_INFO()
18481848

@@ -2121,15 +2121,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_url, 0, 0, 1)
21212121
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, component, IS_LONG, 0, "-1")
21222122
ZEND_END_ARG_INFO()
21232123

2124-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_urlencode, 0, 1, IS_STRING, 0)
2125-
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
2126-
ZEND_END_ARG_INFO()
2124+
#define arginfo_urlencode arginfo_soundex
21272125

2128-
#define arginfo_urldecode arginfo_urlencode
2126+
#define arginfo_urldecode arginfo_soundex
21292127

2130-
#define arginfo_rawurlencode arginfo_urlencode
2128+
#define arginfo_rawurlencode arginfo_soundex
21312129

2132-
#define arginfo_rawurldecode arginfo_urlencode
2130+
#define arginfo_rawurldecode arginfo_soundex
21332131

21342132
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_headers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
21352133
ZEND_ARG_TYPE_INFO(0, url, IS_STRING, 0)

ext/standard/soundex.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ PHP_FUNCTION(soundex)
6060
Z_PARAM_STRING(str, str_len)
6161
ZEND_PARSE_PARAMETERS_END();
6262

63-
if (str_len == 0) {
64-
RETURN_FALSE;
65-
}
66-
6763
/* build soundex string */
6864
last = -1;
6965
for (i = 0, _small = 0; i < str_len && _small < 4; i++) {

ext/standard/tests/strings/soundex.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ foreach ($array as $str) {
3131
echo "Done\n";
3232
?>
3333
--EXPECT--
34-
bool(false)
34+
string(4) "0000"
3535
string(4) "0000"
3636
string(4) "F650"
3737
string(4) "T300"

0 commit comments

Comments
 (0)