summaryrefslogtreecommitdiff
path: root/ext/standard/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r--ext/standard/string.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 8209b56860..e701a9bb0e 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1168,13 +1168,13 @@ PHP_FUNCTION(explode)
}
/* }}} */
-/* {{{ proto string join(array src, string glue)
+/* {{{ proto string join([string glue,] array pieces)
An alias for implode */
/* }}} */
/* {{{ php_implode
*/
-PHPAPI void php_implode(const zend_string *glue, zval *pieces, zval *return_value)
+PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return_value)
{
zval *tmp;
int numelems;
@@ -1187,20 +1187,20 @@ PHPAPI void php_implode(const zend_string *glue, zval *pieces, zval *return_valu
} *strings, *ptr;
ALLOCA_FLAG(use_heap)
- numelems = zend_hash_num_elements(Z_ARRVAL_P(pieces));
+ numelems = zend_hash_num_elements(pieces);
if (numelems == 0) {
RETURN_EMPTY_STRING();
} else if (numelems == 1) {
/* loop to search the first not undefined element... */
- ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(pieces), tmp) {
+ ZEND_HASH_FOREACH_VAL_IND(pieces, tmp) {
RETURN_STR(zval_get_string(tmp));
} ZEND_HASH_FOREACH_END();
}
ptr = strings = do_alloca((sizeof(*strings)) * numelems, use_heap);
- ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(pieces), tmp) {
+ ZEND_HASH_FOREACH_VAL_IND(pieces, tmp) {
if (EXPECTED(Z_TYPE_P(tmp) == IS_STRING)) {
ptr->str = Z_STR_P(tmp);
len += ZSTR_LEN(ptr->str);
@@ -1264,41 +1264,32 @@ PHPAPI void php_implode(const zend_string *glue, zval *pieces, zval *return_valu
Joins array elements placing glue string between items and return one string */
PHP_FUNCTION(implode)
{
- zval *arg1, *arg2 = NULL, *pieces;
- zend_string *glue, *tmp_glue;
+ zend_string *arg1_str = NULL;
+ HashTable *arg1_array = NULL;
+ zend_array *pieces = NULL;
ZEND_PARSE_PARAMETERS_START(1, 2)
- Z_PARAM_ZVAL(arg1)
+ Z_PARAM_STR_OR_ARRAY_HT(arg1_str, arg1_array)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(arg2)
+ Z_PARAM_ARRAY_HT(pieces)
ZEND_PARSE_PARAMETERS_END();
- if (arg2 == NULL) {
- if (Z_TYPE_P(arg1) != IS_ARRAY) {
+ if (pieces == NULL) {
+ if (arg1_array == NULL) {
zend_type_error("Argument must be an array");
return;
}
- glue = ZSTR_EMPTY_ALLOC();
- tmp_glue = NULL;
- pieces = arg1;
+ arg1_str = ZSTR_EMPTY_ALLOC();
+ pieces = arg1_array;
} else {
- if (Z_TYPE_P(arg1) == IS_ARRAY) {
- glue = zval_get_tmp_string(arg2, &tmp_glue);
- pieces = arg1;
- php_error_docref(NULL, E_DEPRECATED,
- "Passing glue string after array is deprecated. Swap the parameters");
- } else if (Z_TYPE_P(arg2) == IS_ARRAY) {
- glue = zval_get_tmp_string(arg1, &tmp_glue);
- pieces = arg2;
- } else {
- zend_type_error("Invalid arguments passed");
+ if (arg1_str == NULL) {
+ zend_type_error("The first argument must be string");
return;
}
}
- php_implode(glue, pieces, return_value);
- zend_tmp_string_release(tmp_glue);
+ php_implode(arg1_str, pieces, return_value);
}
/* }}} */