]> granicus.if.org Git - php/commitdiff
Remove support for mixing parameter order in implode()
authorMáté Kocsis <kocsismate@woohoolabs.com>
Thu, 12 Dec 2019 09:04:31 +0000 (10:04 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Thu, 12 Dec 2019 12:49:05 +0000 (13:49 +0100)
Zend/tests/unexpected_ref_bug.phpt
ext/spl/tests/bug75717.phpt
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/php_string.h
ext/standard/string.c
ext/standard/tests/strings/implode1.phpt
ext/standard/tests/strings/join_variation1.phpt
ext/standard/tests/strings/join_variation2.phpt
ext/standard/tests/strings/join_variation4.phpt
ext/standard/tests/strings/join_variation5.phpt

index a4e74e7a670b6dfccd279eea67ccfc42d4ffbf2b..0d78410d1a91d7550ebd8e23da6fc92ad7a234a7 100644 (file)
@@ -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.
index 485b9d8bc4a0ffe51324bd1f66ad368c49dad25b..77226e10993d8e8b72b9d38233757c633912d47c 100644 (file)
@@ -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"];
index d05b155dab8033aac7db22a2d9cd4760b32afb4e..db6dfb1c74df68ac22bb274468f650c9038b42ad 100755 (executable)
@@ -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 {}
 
index 2fa47cb7041400b6b295acf33c2471fcd89e9ffd..d3f0182bdeaab4c72148936ce12a6ad98f2a97ac 100755 (executable)
@@ -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)
index 6d66e0f1fe9781234d900f32ec4f710f591f4cdf..b7084d09802a5a9ff61c24537ae952ec7105becd 100644 (file)
@@ -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);
index 8209b56860ad47a83d3e6c815ba7d70705a82a6c..e701a9bb0ee60ff7b59a14bcea52278f110f4ed8 100644 (file)
@@ -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);
 }
 /* }}} */
 
index 500bdc6dce5b026a3e7841c8fb68c096a9f48c05..50889265501a53d7ccd7161307042446864f76a7 100644 (file)
Binary files a/ext/standard/tests/strings/implode1.phpt and b/ext/standard/tests/strings/implode1.phpt differ
index 33c519f13ef0196a6deacc636f4339b434435686..db11ff091a1cd9138d14e2d4c2a26274b16671e0 100644 (file)
@@ -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 --
index 16e053cce10ac80b02b04d52487896c336da9bb4..72b5217d0c2bc4a99f446202eef805ede1976525 100644 (file)
@@ -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
index 49cbfa15bce3320029de5f331e0082cf23e674d6..99a791ee561a8340709df4866f50a31dddcf2d92 100644 (file)
Binary files a/ext/standard/tests/strings/join_variation4.phpt and b/ext/standard/tests/strings/join_variation4.phpt differ
index f81524543dacc97c146baba52a9f0210f0ec682b..7880ff07ad314fafd8f42592265b6000aced69fa 100644 (file)
@@ -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