Php ZF2中ViewModel和闭包的奇怪行为
我尝试将回调函数传递给模板,该模板应该在模板中调用,但回调函数是在参数传递给方法setVariable()后直接调用的 结果有点奇怪:Php ZF2中ViewModel和闭包的奇怪行为,php,callback,zend-framework2,Php,Callback,Zend Framework2,我尝试将回调函数传递给模板,该模板应该在模板中调用,但回调函数是在参数传递给方法setVariable()后直接调用的 结果有点奇怪: array(2) { [0] => string(7) "Closure" [1] => string(8) "stdClass" } 我不明白为什么会这样。这是错误还是功能?视图变量存储为自定义ArrayObjectclassZend\view\variables 在调试中调用$viewModel->getVariable()将代理offse
array(2) {
[0] => string(7) "Closure"
[1] => string(8) "stdClass"
}
我不明白为什么会这样。这是错误还是功能?视图变量存储为自定义
ArrayObject
classZend\view\variables
在调试中调用$viewModel->getVariable()
将代理offsetGet
方法和
相关代码
public function offsetGet($key)
{
// ...
$return = parent::offsetGet($key);
// If we have a closure/functor, invoke it, and return its return value
if (is_object($return) && is_callable($return)) {
$return = call_user_func($return);
}
return $return;
}
如果您想要关闭对象,那么您可能需要考虑使用视图助手。
< P>视图变量被存储为自定义<代码> ArrayObject < /Cord>类>代码> ZeNe\View \变量< /C>。p> 在调试中调用$viewModel->getVariable()
将代理offsetGet
方法和
相关代码
public function offsetGet($key)
{
// ...
$return = parent::offsetGet($key);
// If we have a closure/functor, invoke it, and return its return value
if (is_object($return) && is_callable($return)) {
$return = call_user_func($return);
}
return $return;
}
如果您想要关闭对象,那么您可能需要考虑使用视图助手。
不看查看?这显示了在调试过程中调用<代码> GETAVER 导致调用闭包,如果您想要关闭,那么您可能需要考虑视图助手。对我的错误表示感谢。我必须先检查$this->variables类型,然后再提问。不看吗?这显示了在调试过程中调用<代码> GETAVER 导致调用闭包,如果您想要关闭,那么您可能需要考虑视图助手。对我的错误表示感谢。在提问之前,我必须检查$this->variables类型。