Skip to content

Commit 9cea77d

Browse files
committed
Improve readability by using switch
1 parent 8046bf1 commit 9cea77d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ext/standard/string.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,19 +1033,24 @@ PHP_FUNCTION(implode)
10331033
Z_PARAM_ARRAY_HT(pieces)
10341034
ZEND_PARSE_PARAMETERS_END();
10351035

1036-
if (pieces == NULL) {
1037-
if (arg1_array == NULL) {
1038-
zend_type_error("%s(): Argument #1 ($array) must be of type array, string given", get_active_function_name());
1039-
RETURN_THROWS();
1040-
}
1041-
1042-
arg1_str = ZSTR_EMPTY_ALLOC();
1043-
pieces = arg1_array;
1044-
} else {
1045-
if (arg1_str == NULL) {
1046-
zend_argument_type_error(1, "must be of type string, array given");
1047-
RETURN_THROWS();
1048-
}
1036+
switch (ZEND_NUM_ARGS()) {
1037+
case 1:
1038+
if (arg1_array == NULL) {
1039+
zend_type_error("%s(): Argument #1 ($array) must be of type array, string given", get_active_function_name());
1040+
RETURN_THROWS();
1041+
}
1042+
arg1_str = ZSTR_EMPTY_ALLOC();
1043+
pieces = arg1_array;
1044+
break;
1045+
case 2:
1046+
if (arg1_str == NULL) {
1047+
zend_argument_type_error(1, "must be of type string, array given");
1048+
RETURN_THROWS();
1049+
}
1050+
break;
1051+
default:
1052+
// already checked by ZPP
1053+
ZEND_UNREACHABLE();
10491054
}
10501055

10511056
php_implode(arg1_str, pieces, return_value);

0 commit comments

Comments
 (0)