Skip to content

Remove some deprecated functions #4927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Zend/tests/unexpected_ref_bug.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ class Test {
}
$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()));
echo "Done.\n";
?>
--EXPECTF--
Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in %s on line %d
Done.
2 changes: 1 addition & 1 deletion ext/spl/tests/bug75717.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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("", $flat);
}

$noRefs = [[[['some']]],[' nested '],"items"];
Expand Down
7 changes: 2 additions & 5 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,8 @@ 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 {}
/** @param string|array $glue */
function implode($glue, array $pieces = UNKNOWN): string {}

/**
* @param string $str Optional - defaults to previous string
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ 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_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)
Expand Down
16 changes: 5 additions & 11 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,16 +1264,16 @@ 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;
zval *arg1, *pieces = NULL;
zend_string *glue, *tmp_glue;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(arg1)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(arg2)
Z_PARAM_ARRAY(pieces)
ZEND_PARSE_PARAMETERS_END();

if (arg2 == NULL) {
if (pieces == NULL) {
if (Z_TYPE_P(arg1) != IS_ARRAY) {
zend_type_error("Argument must be an array");
return;
Expand All @@ -1283,16 +1283,10 @@ PHP_FUNCTION(implode)
tmp_glue = NULL;
pieces = arg1;
} 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) {
if (Z_TYPE_P(arg1) == IS_STRING) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this changes the behavior: Previously it would cast anything (that isn't an array) to a string, now it strictly requires a string. Ideally it would follow zpp rules...

glue = zval_get_tmp_string(arg1, &tmp_glue);
Copy link
Contributor

@TysonAndre TysonAndre Nov 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also get rid of tmp_glue and zend_tmp_string_release, because Z_PARAM_STR gives you the zend_string

pieces = arg2;
} else {
zend_type_error("Invalid arguments passed");
zend_type_error("The first argument must be string");
return;
}
}
Expand Down
Binary file modified ext/standard/tests/strings/implode1.phpt
Binary file not shown.
76 changes: 30 additions & 46 deletions ext/standard/tests/strings/join_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -103,75 +107,55 @@ echo "Done\n";

--- Testing join() by supplying different values for 'glue' argument ---
-- Iteration 1 --
string(17) "element10element2"
The first argument must be string
-- Iteration 2 --
string(17) "element11element2"
The first argument must be string
-- Iteration 3 --
string(21) "element112345element2"
The first argument must be string
-- Iteration 4 --
string(21) "element1-2345element2"
The first argument must be string
-- Iteration 5 --
string(20) "element110.5element2"
The first argument must be string
-- Iteration 6 --
string(21) "element1-10.5element2"
The first argument must be string
-- Iteration 7 --
string(28) "element1101234567000element2"
The first argument must be string
-- Iteration 8 --
string(29) "element11.07654321E-9element2"
The first argument must be string
-- Iteration 9 --
string(19) "element10.5element2"
The first argument must be string
-- 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"
The first argument must be string
-- Iteration 16 --
string(16) "element1element2"
The first argument must be string
-- Iteration 17 --
string(17) "element11element2"
The first argument must be string
-- Iteration 18 --
string(16) "element1element2"
The first argument must be string
-- Iteration 19 --
string(26) "element1testObjectelement2"
The first argument must be string
-- Iteration 20 --
string(16) "element1element2"
-- Iteration 21 --
string(16) "element1element2"
-- Iteration 22 --
string(16) "element1element2"
The first argument must be string
-- Iteration 23 --
string(16) "element1element2"
The first argument must be string
-- Iteration 24 --
string(%d) "element1Resource id #%delement2"
The first argument must be string
-- Iteration 25 --
string(16) "element1element2"
The first argument must be string
-- Iteration 26 --
string(16) "element1element2"
The first argument must be string
Done
46 changes: 23 additions & 23 deletions ext/standard/tests/strings/join_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified ext/standard/tests/strings/join_variation4.phpt
Binary file not shown.
24 changes: 12 additions & 12 deletions ext/standard/tests/strings/join_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ $sub_array = array(array(1,2,3,4), array(1 => "one", 2 => "two"), "PHP", 50);
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) );
try {
var_dump( join(2, $sub_array) );
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

// using directly the sub_array as pieces
var_dump( join(", ", $sub_array[0]) );
Expand All @@ -37,16 +45,8 @@ 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"

Warning: Array to string conversion in %s on line %d

Warning: Array to string conversion in %s on line %d
string(18) "Array2Array2PHP250"
The first argument must be string
The first argument must be string
string(10) "1, 2, 3, 4"
string(8) "one, two"
Done