diff --git a/NEWS b/NEWS index 23212414d361..40e400247392 100644 --- a/NEWS +++ b/NEWS @@ -224,6 +224,8 @@ PHP NEWS (Weilin Du) . getenv() and putenv() now raises a ValueError when the first argument contains null bytes. (Weilin Du) + . Improved explode() ValueError message when $separator is empty; suggests + str_split() or mb_str_split(). (diegoasales) . parse_str() now raises a ValueError when the $string argument contains null bytes. (Weilin Du) . proc_open() now raises a ValueError when the $cwd argument contains diff --git a/UPGRADING b/UPGRADING index 3d6c89e90e05..95f3a07f58de 100644 --- a/UPGRADING +++ b/UPGRADING @@ -281,6 +281,8 @@ PHP 8.6 UPGRADE NOTES constants). - Standard: + . explode() ValueError message when $separator is empty now suggests + str_split() or mb_str_split(). . ini_get_all() now includes a "builtin_default_value" element for each directive when $details is true. It holds the built-in default value of the directive (or null if it has none), independent of values set in diff --git a/ext/standard/string.c b/ext/standard/string.c index 7ded14366a9f..a19e16bc4a3a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -914,7 +914,7 @@ PHP_FUNCTION(explode) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(delim) == 0) { - zend_argument_must_not_be_empty_error(1); + zend_argument_value_error(1, "must not be empty. Use str_split() or mb_str_split() to split a string into characters"); RETURN_THROWS(); } diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt index ea467a2d5504..83029dc81933 100644 --- a/ext/standard/tests/strings/explode.phpt +++ b/ext/standard/tests/strings/explode.phpt @@ -62,9 +62,9 @@ array ( 4 => 'd', ) d6bee42a771449205344c0938ad4f035 -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters array(1) { [0]=> string(0) "" @@ -79,7 +79,7 @@ array(1) { [0]=> string(0) "" } -explode(): Argument #1 ($separator) must not be empty +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters array(1) { [0]=> string(3) "acb" diff --git a/ext/standard/tests/strings/explode1.phpt b/ext/standard/tests/strings/explode1.phpt index 876b159821cd..ca99f3afc524 100644 --- a/ext/standard/tests/strings/explode1.phpt +++ b/ext/standard/tests/strings/explode1.phpt @@ -91,15 +91,15 @@ var_dump( explode("b", $obj) ); --EXPECT-- *** Testing explode() for basic operations *** -- Iteration 1 -- -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters -- Iteration 2 -- -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters -- Iteration 3 -- array(1) { [0]=> @@ -201,10 +201,10 @@ array(2) { string(56) "234NULL23abcd00000TRUEFALSE-11.234444true-11.24%PHP%ZEND" } -- Iteration 7 -- -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty -explode(): Argument #1 ($separator) must not be empty +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters +explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters -- Iteration 8 -- array(2) { [0]=>