Home > Net >  "Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in"
"Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in"

Time:05-03

I want to run the following command with exec but I am getting an error. So what should I use instead?

 php /var/.../../example.php -- 123456789 exampleData1 exampleData2

Error:

Deprecated: parse_str(): Calling parse_str() without the result argument is deprecated in /var/.../../example.php on line X

I tried this:

$argumentsArray = [
    'postID' => 123456
    'foo' => 'bar'
];

exec(php /var/.../../example.php -- $argumentsArray);

and;

 parse_str(parse_url($argv[0], PHP_URL_QUERY),$arguments);
 $postID = $arguments['postID'];

Error: Notice: Undefined index: postID in..

CodePudding user response:

You can't substitute an entire array into a string. Use implode() to convert an array into a string with a delimiter between the values.

$argumentsArray = [
    'postID' => 123456
    'foo' => 'bar'
];

$arguments = implode(' ', $argumentsArray);

exec("php /var/.../../example.php -- {$arguments}");
  • Related