diff options
-rw-r--r-- | Zend/tests/unexpected_ref_bug.phpt | 9 | ||||
-rw-r--r-- | ext/spl/tests/bug75717.phpt | 2 | ||||
-rwxr-xr-x | ext/standard/basic_functions.stub.php | 6 | ||||
-rwxr-xr-x | ext/standard/basic_functions_arginfo.h | 4 | ||||
-rw-r--r-- | ext/standard/php_string.h | 2 | ||||
-rw-r--r-- | ext/standard/string.c | 43 | ||||
-rw-r--r-- | ext/standard/tests/strings/implode1.phpt | bin | 6042 -> 6069 bytes | |||
-rw-r--r-- | ext/standard/tests/strings/join_variation1.phpt | 40 | ||||
-rw-r--r-- | ext/standard/tests/strings/join_variation2.phpt | 46 | ||||
-rw-r--r-- | ext/standard/tests/strings/join_variation4.phpt | bin | 2319 -> 2256 bytes | |||
-rw-r--r-- | ext/standard/tests/strings/join_variation5.phpt | 22 |
11 files changed, 72 insertions, 102 deletions
diff --git a/Zend/tests/unexpected_ref_bug.phpt b/Zend/tests/unexpected_ref_bug.phpt index a4e74e7a67..0d78410d1a 100644 --- a/Zend/tests/unexpected_ref_bug.phpt +++ b/Zend/tests/unexpected_ref_bug.phpt @@ -9,12 +9,11 @@ class Test { return ","; } } -$my_var = str_repeat("A",64); -$data = call_user_func_array("explode",array(new Test(), &$my_var)); -$my_var=array(1,2,3); -$data = call_user_func_array("implode",array(&$my_var, new Test())); +$my_var = str_repeat("A", 64); +$data = call_user_func_array("explode", array(new Test(), &$my_var)); +$my_var = str_repeat("A", 64); +$data = call_user_func_array("str_replace", array(&$my_var, new Test(), "foo")); echo "Done.\n"; ?> --EXPECTF-- -Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d Done. diff --git a/ext/spl/tests/bug75717.phpt b/ext/spl/tests/bug75717.phpt index 485b9d8bc4..77226e1099 100644 --- a/ext/spl/tests/bug75717.phpt +++ b/ext/spl/tests/bug75717.phpt @@ -8,7 +8,7 @@ function flatten(array $nestedArraysAndStrings){ $iter = new RecursiveIteratorIterator( new RecursiveArrayIterator($nestedArraysAndStrings)); foreach($iter as $leaf){ $flat[] = $leaf; } - return join(NULL, $flat); + return join(null, $flat); } $noRefs = [[[['some']]],[' nested '],"items"]; diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index d05b155dab..db6dfb1c74 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -535,11 +535,7 @@ function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut function explode(string $separator, string $str, int $limit = PHP_INT_MAX): array {} -/** - * @param string $glue Optional - defaults to empty string - * @param array $pieces - */ -function implode($glue, $pieces = UNKNOWN): string {} +function implode(string|array $glue, array $pieces = UNKNOWN): string {} function strtok(string $str, string $token = UNKNOWN): string|false {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 2fa47cb704..d3f0182bde 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -841,8 +841,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_explode, 0, 2, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_implode, 0, 1, IS_STRING, 0) - ZEND_ARG_INFO(0, glue) - ZEND_ARG_INFO(0, pieces) + ZEND_ARG_TYPE_MASK(0, glue, MAY_BE_STRING|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, pieces, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtok, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 6d66e0f1fe..b7084d0980 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -125,7 +125,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const ch PHPAPI zend_string *php_trim(zend_string *str, char *what, size_t what_len, int mode); PHPAPI size_t php_strip_tags(char *rbuf, size_t len, uint8_t *state, const char *allow, size_t allow_len); PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const char *allow, size_t allow_len, zend_bool allow_tag_spaces); -PHPAPI void php_implode(const zend_string *delim, zval *arr, zval *return_value); +PHPAPI void php_implode(const zend_string *delim, HashTable *arr, zval *return_value); PHPAPI void php_explode(const zend_string *delim, zend_string *str, zval *return_value, zend_long limit); PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end); 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); } /* }}} */ diff --git a/ext/standard/tests/strings/implode1.phpt b/ext/standard/tests/strings/implode1.phpt Binary files differindex 500bdc6dce..5088926550 100644 --- a/ext/standard/tests/strings/implode1.phpt +++ b/ext/standard/tests/strings/implode1.phpt diff --git a/ext/standard/tests/strings/join_variation1.phpt b/ext/standard/tests/strings/join_variation1.phpt index 33c519f13e..db11ff091a 100644 --- a/ext/standard/tests/strings/join_variation1.phpt +++ b/ext/standard/tests/strings/join_variation1.phpt @@ -91,9 +91,13 @@ for($index = 0; $index < count($values); $index ++) { echo "-- Iteration $counter --\n"; $glue = $values [$index]; - var_dump( join($glue, $pieces) ); + try { + var_dump(join($glue, $pieces)); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } - $counter ++; + $counter++; } echo "Done\n"; @@ -121,35 +125,15 @@ string(29) "element11.07654321E-9element2" -- Iteration 9 -- string(19) "element10.5element2" -- Iteration 10 -- - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(0) "" +The first argument must be string -- Iteration 11 -- - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(1) "0" +The first argument must be string -- Iteration 12 -- - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(1) "1" +The first argument must be string -- Iteration 13 -- - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(7) "1Array2" +The first argument must be string -- Iteration 14 -- - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(11) "redArraypen" +The first argument must be string -- Iteration 15 -- string(17) "element11element2" -- Iteration 16 -- @@ -169,7 +153,7 @@ string(16) "element1element2" -- Iteration 23 -- string(16) "element1element2" -- Iteration 24 -- -string(%d) "element1Resource id #%delement2" +join() expects parameter 1 to be string or array, resource given -- Iteration 25 -- string(16) "element1element2" -- Iteration 26 -- diff --git a/ext/standard/tests/strings/join_variation2.phpt b/ext/standard/tests/strings/join_variation2.phpt index 16e053cce1..72b5217d0c 100644 --- a/ext/standard/tests/strings/join_variation2.phpt +++ b/ext/standard/tests/strings/join_variation2.phpt @@ -108,49 +108,49 @@ echo "Done\n"; --- Testing join() by supplying different values for 'pieces' argument --- -- Iteration 1 -- -Invalid arguments passed +join() expects parameter 2 to be array, int given -- Iteration 2 -- -Invalid arguments passed +join() expects parameter 2 to be array, int given -- Iteration 3 -- -Invalid arguments passed +join() expects parameter 2 to be array, int given -- Iteration 4 -- -Invalid arguments passed +join() expects parameter 2 to be array, int given -- Iteration 5 -- -Invalid arguments passed +join() expects parameter 2 to be array, float given -- Iteration 6 -- -Invalid arguments passed +join() expects parameter 2 to be array, float given -- Iteration 7 -- -Invalid arguments passed +join() expects parameter 2 to be array, float given -- Iteration 8 -- -Invalid arguments passed +join() expects parameter 2 to be array, float given -- Iteration 9 -- -Invalid arguments passed +join() expects parameter 2 to be array, float given -- Iteration 10 -- -Invalid arguments passed +join() expects parameter 2 to be array, bool given -- Iteration 11 -- -Invalid arguments passed +join() expects parameter 2 to be array, bool given -- Iteration 12 -- -Invalid arguments passed +join() expects parameter 2 to be array, bool given -- Iteration 13 -- -Invalid arguments passed +join() expects parameter 2 to be array, bool given -- Iteration 14 -- -Invalid arguments passed +join() expects parameter 2 to be array, string given -- Iteration 15 -- -Invalid arguments passed +join() expects parameter 2 to be array, string given -- Iteration 16 -- -Invalid arguments passed +join() expects parameter 2 to be array, object given -- Iteration 17 -- -Invalid arguments passed +join() expects parameter 2 to be array, string given -- Iteration 18 -- -Invalid arguments passed +join() expects parameter 2 to be array, string given -- Iteration 19 -- -Invalid arguments passed +join() expects parameter 2 to be array, null given -- Iteration 20 -- -Invalid arguments passed +join() expects parameter 2 to be array, null given -- Iteration 21 -- -Invalid arguments passed +join() expects parameter 2 to be array, resource given -- Iteration 22 -- -Invalid arguments passed +join() expects parameter 2 to be array, null given -- Iteration 23 -- -Invalid arguments passed +join() expects parameter 2 to be array, null given Done diff --git a/ext/standard/tests/strings/join_variation4.phpt b/ext/standard/tests/strings/join_variation4.phpt Binary files differindex 49cbfa15bc..99a791ee56 100644 --- a/ext/standard/tests/strings/join_variation4.phpt +++ b/ext/standard/tests/strings/join_variation4.phpt diff --git a/ext/standard/tests/strings/join_variation5.phpt b/ext/standard/tests/strings/join_variation5.phpt index f81524543d..7880ff07ad 100644 --- a/ext/standard/tests/strings/join_variation5.phpt +++ b/ext/standard/tests/strings/join_variation5.phpt @@ -16,17 +16,21 @@ echo "*** Testing implode() : usage variations - sub arrays ***\n"; $sub_array = array(array(1,2,3,4), array(1 => "one", 2 => "two"), "PHP", 50); // pieces as array containing sub array -var_dump( join("TEST", $sub_array) ); +var_dump(join("TEST", $sub_array)); // glue as array & pieces as array containing sub array -var_dump( join(array(1, 2, 3, 4), $sub_array) ); +try { + var_dump(join(array(1, 2, 3, 4), $sub_array)); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -// numeric value as glue, pieces as array containg sub array -var_dump( join(2, $sub_array) ); +// numeric value as glue, pieces as array containing sub array +var_dump(join(2, $sub_array)); // using directly the sub_array as pieces -var_dump( join(", ", $sub_array[0]) ); -var_dump( join(", ", $sub_array[1]) ); +var_dump(join(", ", $sub_array[0])); +var_dump(join(", ", $sub_array[1])); echo "Done\n"; ?> @@ -37,11 +41,7 @@ Warning: Array to string conversion in %s on line %d Warning: Array to string conversion in %s on line %d string(27) "ArrayTESTArrayTESTPHPTEST50" - -Warning: Array to string conversion in %s on line %d - -Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d -string(19) "1Array2Array3Array4" +The first argument must be string Warning: Array to string conversion in %s on line %d |