Skip to content

Commit 65b087b

Browse files
committed
Remove support for mixing parameter order in implode()
1 parent 5b9725e commit 65b087b

File tree

9 files changed

+73
-101
lines changed

9 files changed

+73
-101
lines changed

Zend/tests/unexpected_ref_bug.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ class Test {
1111
}
1212
$my_var = str_repeat("A",64);
1313
$data = call_user_func_array("explode",array(new Test(), &$my_var));
14-
$my_var=array(1,2,3);
15-
$data = call_user_func_array("implode",array(&$my_var, new Test()));
1614
echo "Done.\n";
1715
?>
1816
--EXPECTF--
19-
Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
2017
Done.

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,8 @@ function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut
543543

544544
function explode(string $separator, string $str, int $limit = PHP_INT_MAX): array {}
545545

546-
/**
547-
* @param string $glue Optional - defaults to empty string
548-
* @param array $pieces
549-
*/
550-
function implode($glue, $pieces = UNKNOWN): string {}
546+
/** @param string|array $glue */
547+
function implode($glue, array $pieces = UNKNOWN): string {}
551548

552549
/**
553550
* @param string $str Optional - defaults to previous string

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ ZEND_END_ARG_INFO()
852852

853853
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_implode, 0, 1, IS_STRING, 0)
854854
ZEND_ARG_INFO(0, glue)
855-
ZEND_ARG_INFO(0, pieces)
855+
ZEND_ARG_TYPE_INFO(0, pieces, IS_ARRAY, 0)
856856
ZEND_END_ARG_INFO()
857857

858858
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtok, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)

ext/standard/string.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,16 +1264,16 @@ PHPAPI void php_implode(const zend_string *glue, zval *pieces, zval *return_valu
12641264
Joins array elements placing glue string between items and return one string */
12651265
PHP_FUNCTION(implode)
12661266
{
1267-
zval *arg1, *arg2 = NULL, *pieces;
1267+
zval *arg1, *pieces = NULL;
12681268
zend_string *glue, *tmp_glue;
12691269

12701270
ZEND_PARSE_PARAMETERS_START(1, 2)
12711271
Z_PARAM_ZVAL(arg1)
12721272
Z_PARAM_OPTIONAL
1273-
Z_PARAM_ZVAL(arg2)
1273+
Z_PARAM_ARRAY(pieces)
12741274
ZEND_PARSE_PARAMETERS_END();
12751275

1276-
if (arg2 == NULL) {
1276+
if (pieces == NULL) {
12771277
if (Z_TYPE_P(arg1) != IS_ARRAY) {
12781278
zend_type_error("Argument must be an array");
12791279
return;
@@ -1283,16 +1283,10 @@ PHP_FUNCTION(implode)
12831283
tmp_glue = NULL;
12841284
pieces = arg1;
12851285
} else {
1286-
if (Z_TYPE_P(arg1) == IS_ARRAY) {
1287-
glue = zval_get_tmp_string(arg2, &tmp_glue);
1288-
pieces = arg1;
1289-
php_error_docref(NULL, E_DEPRECATED,
1290-
"Passing glue string after array is deprecated. Swap the parameters");
1291-
} else if (Z_TYPE_P(arg2) == IS_ARRAY) {
1286+
if (Z_TYPE_P(arg1) == IS_STRING) {
12921287
glue = zval_get_tmp_string(arg1, &tmp_glue);
1293-
pieces = arg2;
12941288
} else {
1295-
zend_type_error("Invalid arguments passed");
1289+
zend_type_error("The first argument must be string");
12961290
return;
12971291
}
12981292
}
-85 Bytes
Binary file not shown.

ext/standard/tests/strings/join_variation1.phpt

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ for($index = 0; $index < count($values); $index ++) {
9191
echo "-- Iteration $counter --\n";
9292
$glue = $values [$index];
9393

94-
var_dump( join($glue, $pieces) );
94+
try {
95+
var_dump(join($glue, $pieces));
96+
} catch (TypeError $exception) {
97+
echo $exception->getMessage() . "\n";
98+
}
9599

96-
$counter ++;
100+
$counter++;
97101
}
98102

99103
echo "Done\n";
@@ -103,75 +107,55 @@ echo "Done\n";
103107

104108
--- Testing join() by supplying different values for 'glue' argument ---
105109
-- Iteration 1 --
106-
string(17) "element10element2"
110+
The first argument must be string
107111
-- Iteration 2 --
108-
string(17) "element11element2"
112+
The first argument must be string
109113
-- Iteration 3 --
110-
string(21) "element112345element2"
114+
The first argument must be string
111115
-- Iteration 4 --
112-
string(21) "element1-2345element2"
116+
The first argument must be string
113117
-- Iteration 5 --
114-
string(20) "element110.5element2"
118+
The first argument must be string
115119
-- Iteration 6 --
116-
string(21) "element1-10.5element2"
120+
The first argument must be string
117121
-- Iteration 7 --
118-
string(28) "element1101234567000element2"
122+
The first argument must be string
119123
-- Iteration 8 --
120-
string(29) "element11.07654321E-9element2"
124+
The first argument must be string
121125
-- Iteration 9 --
122-
string(19) "element10.5element2"
126+
The first argument must be string
123127
-- Iteration 10 --
124-
125-
Warning: Array to string conversion in %s on line %d
126-
127-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
128-
string(0) ""
128+
The first argument must be string
129129
-- Iteration 11 --
130-
131-
Warning: Array to string conversion in %s on line %d
132-
133-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
134-
string(1) "0"
130+
The first argument must be string
135131
-- Iteration 12 --
136-
137-
Warning: Array to string conversion in %s on line %d
138-
139-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
140-
string(1) "1"
132+
The first argument must be string
141133
-- Iteration 13 --
142-
143-
Warning: Array to string conversion in %s on line %d
144-
145-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
146-
string(7) "1Array2"
134+
The first argument must be string
147135
-- Iteration 14 --
148-
149-
Warning: Array to string conversion in %s on line %d
150-
151-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
152-
string(11) "redArraypen"
136+
The first argument must be string
153137
-- Iteration 15 --
154-
string(17) "element11element2"
138+
The first argument must be string
155139
-- Iteration 16 --
156-
string(16) "element1element2"
140+
The first argument must be string
157141
-- Iteration 17 --
158-
string(17) "element11element2"
142+
The first argument must be string
159143
-- Iteration 18 --
160-
string(16) "element1element2"
144+
The first argument must be string
161145
-- Iteration 19 --
162-
string(26) "element1testObjectelement2"
146+
The first argument must be string
163147
-- Iteration 20 --
164148
string(16) "element1element2"
165149
-- Iteration 21 --
166150
string(16) "element1element2"
167151
-- Iteration 22 --
168-
string(16) "element1element2"
152+
The first argument must be string
169153
-- Iteration 23 --
170-
string(16) "element1element2"
154+
The first argument must be string
171155
-- Iteration 24 --
172-
string(%d) "element1Resource id #%delement2"
156+
The first argument must be string
173157
-- Iteration 25 --
174-
string(16) "element1element2"
158+
The first argument must be string
175159
-- Iteration 26 --
176-
string(16) "element1element2"
160+
The first argument must be string
177161
Done

ext/standard/tests/strings/join_variation2.phpt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,49 +108,49 @@ echo "Done\n";
108108

109109
--- Testing join() by supplying different values for 'pieces' argument ---
110110
-- Iteration 1 --
111-
Invalid arguments passed
111+
join() expects parameter 2 to be array, int given
112112
-- Iteration 2 --
113-
Invalid arguments passed
113+
join() expects parameter 2 to be array, int given
114114
-- Iteration 3 --
115-
Invalid arguments passed
115+
join() expects parameter 2 to be array, int given
116116
-- Iteration 4 --
117-
Invalid arguments passed
117+
join() expects parameter 2 to be array, int given
118118
-- Iteration 5 --
119-
Invalid arguments passed
119+
join() expects parameter 2 to be array, float given
120120
-- Iteration 6 --
121-
Invalid arguments passed
121+
join() expects parameter 2 to be array, float given
122122
-- Iteration 7 --
123-
Invalid arguments passed
123+
join() expects parameter 2 to be array, float given
124124
-- Iteration 8 --
125-
Invalid arguments passed
125+
join() expects parameter 2 to be array, float given
126126
-- Iteration 9 --
127-
Invalid arguments passed
127+
join() expects parameter 2 to be array, float given
128128
-- Iteration 10 --
129-
Invalid arguments passed
129+
join() expects parameter 2 to be array, bool given
130130
-- Iteration 11 --
131-
Invalid arguments passed
131+
join() expects parameter 2 to be array, bool given
132132
-- Iteration 12 --
133-
Invalid arguments passed
133+
join() expects parameter 2 to be array, bool given
134134
-- Iteration 13 --
135-
Invalid arguments passed
135+
join() expects parameter 2 to be array, bool given
136136
-- Iteration 14 --
137-
Invalid arguments passed
137+
join() expects parameter 2 to be array, string given
138138
-- Iteration 15 --
139-
Invalid arguments passed
139+
join() expects parameter 2 to be array, string given
140140
-- Iteration 16 --
141-
Invalid arguments passed
141+
join() expects parameter 2 to be array, object given
142142
-- Iteration 17 --
143-
Invalid arguments passed
143+
join() expects parameter 2 to be array, string given
144144
-- Iteration 18 --
145-
Invalid arguments passed
145+
join() expects parameter 2 to be array, string given
146146
-- Iteration 19 --
147-
Invalid arguments passed
147+
join() expects parameter 2 to be array, null given
148148
-- Iteration 20 --
149-
Invalid arguments passed
149+
join() expects parameter 2 to be array, null given
150150
-- Iteration 21 --
151-
Invalid arguments passed
151+
join() expects parameter 2 to be array, resource given
152152
-- Iteration 22 --
153-
Invalid arguments passed
153+
join() expects parameter 2 to be array, null given
154154
-- Iteration 23 --
155-
Invalid arguments passed
155+
join() expects parameter 2 to be array, null given
156156
Done
-298 Bytes
Binary file not shown.

ext/standard/tests/strings/join_variation5.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ $sub_array = array(array(1,2,3,4), array(1 => "one", 2 => "two"), "PHP", 50);
1919
var_dump( join("TEST", $sub_array) );
2020

2121
// glue as array & pieces as array containing sub array
22-
var_dump( join(array(1, 2, 3, 4), $sub_array) );
22+
try {
23+
var_dump( join(array(1, 2, 3, 4), $sub_array) );
24+
} catch (TypeError $exception) {
25+
echo $exception->getMessage() . "\n";
26+
}
2327

2428
// numeric value as glue, pieces as array containg sub array
25-
var_dump( join(2, $sub_array) );
29+
try {
30+
var_dump( join(2, $sub_array) );
31+
} catch (TypeError $exception) {
32+
echo $exception->getMessage() . "\n";
33+
}
2634

2735
// using directly the sub_array as pieces
2836
var_dump( join(", ", $sub_array[0]) );
@@ -37,16 +45,8 @@ Warning: Array to string conversion in %s on line %d
3745

3846
Warning: Array to string conversion in %s on line %d
3947
string(27) "ArrayTESTArrayTESTPHPTEST50"
40-
41-
Warning: Array to string conversion in %s on line %d
42-
43-
Deprecated: join(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
44-
string(19) "1Array2Array3Array4"
45-
46-
Warning: Array to string conversion in %s on line %d
47-
48-
Warning: Array to string conversion in %s on line %d
49-
string(18) "Array2Array2PHP250"
48+
The first argument must be string
49+
The first argument must be string
5050
string(10) "1, 2, 3, 4"
5151
string(8) "one, two"
5252
Done

0 commit comments

Comments
 (0)