Skip to content

Commit 76ac618

Browse files
committed
Implement frameless handlers for implode
1 parent 43222b5 commit 76ac618

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

Zend/zend_frameless_function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
zend_wrong_parameter_type_error(arg_num, Z_EXPECTED_ARRAY, arg ## arg_num); \
4949
goto flf_clean; \
5050
}
51+
#define Z_FLF_PARAM_ARRAY_OR_NULL(arg_num, dest) \
52+
if (!zend_parse_arg_array(arg ## arg_num, &dest, /* null_check */ true, /* or_object */ false)) { \
53+
zend_wrong_parameter_type_error(arg_num, Z_EXPECTED_ARRAY_OR_NULL, arg ## arg_num); \
54+
goto flf_clean; \
55+
}
5156
#define Z_FLF_PARAM_BOOL(arg_num, dest) \
5257
if (!zend_parse_arg_bool_ex(arg ## arg_num, &dest, /* is_null */ NULL, /* null_check */ false, arg_num, /* frameless */ true)) { \
5358
zend_wrong_parameter_type_error(arg_num, Z_EXPECTED_BOOL, arg ## arg_num); \

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,8 @@ function explode(string $separator, string $string, int $limit = PHP_INT_MAX): a
23322332

23332333
/**
23342334
* @compile-time-eval
2335+
* @frameless-function {"arity": 1}
2336+
* @frameless-function {"arity": 2}
23352337
*/
23362338
function implode(string|array $separator, ?array $array = null): string {}
23372339

ext/standard/basic_functions_arginfo.h

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/string.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,43 @@ PHP_FUNCTION(implode)
10521052
}
10531053
/* }}} */
10541054

1055+
ZEND_FRAMELESS_FUNCTION(implode, 1)
1056+
{
1057+
zval *pieces;
1058+
1059+
/* Manual parsing for more accurate error message. */
1060+
if (!zend_parse_arg_array(arg1, &pieces, /* null_check */ false, /* or_object */ false)) { \
1061+
zend_type_error("%s(): Argument #1 ($array) must be of type array, %s given", get_active_function_name(), zend_zval_value_name(arg1));
1062+
goto flf_clean; \
1063+
}
1064+
1065+
zend_string *str = ZSTR_EMPTY_ALLOC();
1066+
1067+
php_implode(str, Z_ARR_P(pieces), return_value);
1068+
1069+
flf_clean:;
1070+
}
1071+
1072+
ZEND_FRAMELESS_FUNCTION(implode, 2)
1073+
{
1074+
zval str_tmp;
1075+
zend_string *str;
1076+
zval *pieces;
1077+
1078+
Z_FLF_PARAM_STR(1, str, str_tmp);
1079+
Z_FLF_PARAM_ARRAY_OR_NULL(2, pieces);
1080+
1081+
if (!pieces) {
1082+
zend_type_error("%s(): Argument #1 ($array) must be of type array, %s given", get_active_function_name(), zend_zval_value_name(arg1));
1083+
goto flf_clean;
1084+
}
1085+
1086+
php_implode(str, Z_ARR_P(pieces), return_value);
1087+
1088+
flf_clean:;
1089+
Z_FLF_PARAM_FREE_STR(1, str_tmp);
1090+
}
1091+
10551092
#define STRTOK_TABLE(p) BG(strtok_table)[(unsigned char) *p]
10561093

10571094
/* {{{ Tokenize a string */

0 commit comments

Comments
 (0)