vimal1083
vimal1083

Reputation: 8661

php Strict Standards: Only variables should be passed by reference in "use"

While working I met this annoying message

Strict Standards: Only variables should be passed by reference in G:\xampp\htdocs\MyProject\ZendSkeletonApplication\module\Admission\src\Admission\Controller\AdmissionController.php on line 107

My code

$consoldatedCities = '';

array_walk_recursive(
    $StateCityHash,
    function($cityName, $cityId) use (&$consoldatedCities) {
        $consoldatedCities[$cityId] = $cityName;
    }
); // line 107

This is to convert multidimensional array into simple array .

But the code works as I expected. Can anyone tell me how to solve this problem?

Upvotes: 0

Views: 1372

Answers (1)

Anna T
Anna T

Reputation: 955

Here http://php.net/manual/en/language.references.pass.php it says that "There is no reference sign on a function call - only on function definitions." Try removing the '&' from your function call code there and see if that gets rid of the message.

---Edit---

Looking at this thread here "Strict Standards: Only variables should be passed by reference" error

you could try saving your callback function into a variable before passing it to the array walk function:

$consoldatedCities=array();

$callbackFcn= 
   function($cityName,$cityId) use(&$consoldatedCities)
   {
      $consoldatedCities[$cityId] = $cityName; 
   };

array_walk_recursive($StateCityHash, $callbackFcn);

Upvotes: 0

Related Questions