【问题标题】:php Strict Standards: Only variables should be passed by reference in "use"php 严格标准:在“使用”中只能通过引用传递变量
【发布时间】:2013-08-14 03:04:33
【问题描述】:

在工作时我遇到了这个烦人的消息

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

我的代码

$consoldatedCities='';

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

这是将多维数组转换为简单数组

但代码按我的预期工作.. 谁能告诉我如何解决这个问题

【问题讨论】:

标签: standards php-5.3 strict


【解决方案1】:

这里http://php.net/manual/en/language.references.pass.php 说“函数调用没有参考符号 - 仅在函数定义上。”尝试从那里的函数调用代码中删除“&”,看看是否消除了该消息。

---编辑---

在这里看这个帖子"Strict Standards: Only variables should be passed by reference" error

您可以尝试将回调函数保存到变量中,然后再将其传递给数组遍历函数:

$consoldatedCities=array();

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

array_walk_recursive($StateCityHash, $callbackFcn);

【讨论】:

  • 感谢您的即时回复。如果我从函数调用中删除“&”,“$consoldatedCities”将为空
  • 谢谢,我仍然在这一行 array_walk_recursive($StateCityHash, $callbackFcn); 中遇到同样的错误。在这里,我们刚刚在$callbackFcn 中分配了相同的功能,所以它也会导致同样的错误。我认为我必须还原并使用foreach 做一些事情。
猜你喜欢
  • 2013-05-21
  • 1970-01-01
  • 2020-07-02
  • 2017-07-24
  • 1970-01-01
  • 2012-12-24
  • 2014-02-10
相关资源
最近更新 更多