Skip to content

Commit 6bc6a84

Browse files
committed
Improve readability by using switch
1 parent e2810b5 commit 6bc6a84

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
@@ -1236,19 +1236,24 @@ PHP_FUNCTION(implode)
12361236
Z_PARAM_ARRAY_HT(pieces)
12371237
ZEND_PARSE_PARAMETERS_END();
12381238

1239-
if (pieces == NULL) {
1240-
if (arg1_array == NULL) {
1241-
zend_type_error("%s(): Argument #1 ($array) must be of type array, string given", get_active_function_name());
1242-
RETURN_THROWS();
1243-
}
1244-
1245-
arg1_str = ZSTR_EMPTY_ALLOC();
1246-
pieces = arg1_array;
1247-
} else {
1248-
if (arg1_str == NULL) {
1249-
zend_argument_type_error(1, "must be of type string, array given");
1250-
RETURN_THROWS();
1251-
}
1239+
switch (ZEND_NUM_ARGS()) {
1240+
case 1:
1241+
if (arg1_array == NULL) {
1242+
zend_type_error("%s(): Argument #1 ($array) must be of type array, string given", get_active_function_name());
1243+
RETURN_THROWS();
1244+
}
1245+
arg1_str = ZSTR_EMPTY_ALLOC();
1246+
pieces = arg1_array;
1247+
break;
1248+
case 2:
1249+
if (arg1_str == NULL) {
1250+
zend_argument_type_error(1, "must be of type string, array given");
1251+
RETURN_THROWS();
1252+
}
1253+
break;
1254+
default:
1255+
// already checked by ZPP
1256+
ZEND_UNREACHABLE();
12521257
}
12531258

12541259
php_implode(arg1_str, pieces, return_value);

0 commit comments

Comments
 (0)