Skip to content

Commit

Permalink
Don't return false for empty string in soundex()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Sep 22, 2020
1 parent f26d855 commit aba0ee7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
14 changes: 6 additions & 8 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions ext/standard/soundex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/strings/soundex.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit aba0ee7

Please sign in to comment.