【发布时间】:2015-01-08 10:36:32
【问题描述】:
如果可能,我正在尝试找到一种方法来使示例 2 工作。有人能帮帮我吗?
打电话
$this->getValue('getName');
$this->getValue('getEmail');
示例 1(工作)
private function getValue($method)
{
$o = new Order();
$p = $o->Payment();
return $p->$method(); // Works
return $p->call_user_func($method); // Works
}
示例 2(不起作用)
private function getValue($method)
{
return
new Closure(function (Order $o) {
if ($o->getPayment() instanceof Payment) {
return $o->Payment()->$method(); // Don't Work
return $o->Payment()->call_user_func($method); // Don't Work
}
});
}
【问题讨论】:
-
$o->getPayment()和$o->Payment()有什么区别? -
没有区别,但它可以稍后删除,所以现在不是问题。
-
顺便说一句,
Closures disallow 直接实例化。