2

When running the following code:

<?php
    $output = array();
    exec("ping google.com", &$output);
    foreach ($output as $key => $value) {
        echo $value . "<br/>";
    }
?>

Getting Deprecated: as follows

 Call-time pass-by-reference has been deprecated in C:\xampp\htdocs\my_test\ajax_loop.php on line 3.

Please help.

DevT
  • 4,843
  • 16
  • 59
  • 92
Airful
  • 312
  • 2
  • 12
  • Read a note [here](http://php.net/manual/en/language.references.pass.php) – Gowri Jun 11 '12 at 11:58
  • related questions http://stackoverflow.com/questions/4665782/call-time-pass-by-reference-has-been-deprecated and http://stackoverflow.com/questions/6276451/deprecated-call-time-pass-by-reference-has-been-deprecated-in should have searched first – dakdad Jun 11 '12 at 11:58

2 Answers2

1

You need to drop the reference operator from &$output indeed.

Few tutorials provides the syntax of functions as follows (exec in this example).

string exec ( string $command [, array &$output [, int &$return_var ]] ) .

The '&' is not a reference operator, it only indicates that they are output variables, meaning you can expect the values of these variables to be populated with output data after the function call. In this case after the function call the $output array will be filled with all lines of output from the commnad which you try to execute. The $return_var will have the return status.

iblue
  • 29,609
  • 19
  • 89
  • 128
payyans
  • 96
  • 4
0

Just drop the reference operator, it is not needed:

...
exec("ping google.com", $output);
...
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92