Skip to content

Commit ee0be5f

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

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

ext/standard/string.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,19 +1236,22 @@ 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+
break;
1246+
case 2:
1247+
if (arg1_str == NULL) {
1248+
zend_argument_type_error(1, "must be of type string, array given");
1249+
RETURN_THROWS();
1250+
}
1251+
break;
1252+
default:
1253+
// already checked by ZPP
1254+
ZEND_UNREACHABLE();
12521255
}
12531256

12541257
php_implode(arg1_str, pieces, return_value);

0 commit comments

Comments
 (0)