Skip to content

Commit 54ad47f

Browse files
Rewriting the error message and moving test conditions
1 parent ea01f5f commit 54ad47f

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

ext/standard/string.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,11 @@ PHP_FUNCTION(implode)
10341034
ZEND_PARSE_PARAMETERS_END();
10351035

10361036
if (arg1_str != NULL && pieces == NULL) {
1037-
zend_type_error("%s(): Argument #2 ($array) must be of type array, null given", get_active_function_name());
1037+
zend_type_error(
1038+
"%s(): If argument #1 ($separator) is of type string, "
1039+
"argument #2 ($array) must be of type array, null given",
1040+
get_active_function_name()
1041+
);
10381042
RETURN_THROWS();
10391043
}
10401044

ext/standard/tests/strings/implode_error.phpt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,13 @@ try {
88
echo $e->getMessage(), "\n";
99
}
1010

11-
/* int as pieces */
12-
try {
13-
var_dump( implode("glue",1234) );
14-
} catch (TypeError $e) {
15-
echo $e->getMessage(), "\n";
16-
}
17-
1811
/* NULL as pieces */
1912
try {
2013
var_dump( implode("glue", NULL) );
2114
} catch (TypeError $e) {
2215
echo $e->getMessage(), "\n";
2316
}
2417

25-
/* pieces as NULL array */
26-
try {
27-
var_dump( implode(",", array(NULL)) );
28-
} catch (TypeError $e) {
29-
echo $e->getMessage(), "\n";
30-
}
31-
3218
/* integer as glue */
3319
try {
3420
var_dump( implode(12, "pieces") );
@@ -45,9 +31,7 @@ try {
4531
?>
4632
--EXPECTF--
4733
implode(): Argument #2 ($array) must be of type array, null given
48-
implode(): Argument #2 ($array) must be of type array, int given
4934
implode(): Argument #2 ($array) must be of type array, null given
50-
string(0) ""
5135
implode(): Argument #2 ($array) must be of type array, string given
5236

5337
Deprecated: implode(): Passing null to parameter #1 ($separator) of type array|string is deprecated in %s on line %d

ext/standard/tests/strings/implode1.phpt renamed to ext/standard/tests/strings/implode_variation.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $arrays = array (
99
array(array(2),array(1)),
1010
array(false,true),
1111
array(),
12-
array("a","aaaa","b","bbbb","c","ccccccccccccccccccccc")
12+
array("a","aaaa","b","bbbb","c","ccccccccccccccccccccc"),
13+
array(NULL),
1314
);
1415
/* loop to output string with ', ' as $glue, using implode() */
1516
foreach ($arrays as $array) {
@@ -170,6 +171,11 @@ array(6) {
170171
[5]=>
171172
string(21) "ccccccccccccccccccccc"
172173
}
174+
string(0) ""
175+
array(1) {
176+
[0]=>
177+
NULL
178+
}
173179

174180
*** Testing implode() with variations of glue ***
175181
-- Iteration 1 --

0 commit comments

Comments
 (0)