Getting Deprecated: Call-time pass-by-reference has been deprecated when calling exec() Function

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.

Answers


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.


Just drop the reference operator, it is not needed:

...
exec("ping google.com", $output);
...

Need Your Help

how to retrieve data from MySQL using javascript

php javascript ajax

I have a web page coded in PHP. This page is for posting a request for services. All services are stored in two separate tables along with prices.

C++ static initialization order

c++ static-variables static-order-fiasco initialization-order

When I use static variables in C++, I often end up wanting to initialize one variable passing another to its constructor. In other words, I want to create static instances that depend on each other...