【问题标题】:Ambigous PHP error message [duplicate]模棱两可的PHP错误消息[重复]
【发布时间】:2015-06-13 09:38:33
【问题描述】:

有这个:

...
private $responseBuffer = array();
...

在这一行内:

$lm = end(array_values($this->responseBuffer));

我明白了

Error: Only variables should be passed by reference (2048)

因为endarray_values 都是内置的,没有call-by-reference我很困惑,有人知道吗?

(目的:获取$responseBuffer的最新值)

【问题讨论】:

  • 你需要一个变量 - $foo = array_values($this->responseBuffer); $lm = end($foo);, end 的第一个参数是 ref
  • @Clive 哎呀,我没看到你已经回答了..
  • 我没有@xurshid29,把你的留在那里;)
  • 这里解释了为什么在传递给end之前需要将array_values分配给变量 - stackoverflow.com/a/4636183/1426354

标签: php


【解决方案1】:

end函数通过引用接收参数,这样做:

$var = array_values($this->responseBuffer);
$lm = end($var);

【讨论】:

  • 是的,谢谢,只需阅读手册,就像 RTFM 一样...
猜你喜欢
  • 1970-01-01
  • 2010-09-30
  • 1970-01-01
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
相关资源
最近更新 更多