【发布时间】:2012-02-08 21:21:57
【问题描述】:
如果我有这样的课程:
class test{
function one(){
$this->two()->func(); //Since $test is returned, why can I not call func()?
}
function two(){
$test = (object) array();
$test->func = function(){
echo 'Does this work?';
};
return $test;
}
}
$new = new test;
$new->one(); //Expecting 'Does this work?'
所以我的问题是,当我从函数一调用函数二时,函数二返回 $test 变量,该变量附加了一个 func() 闭包函数。为什么我不能将其称为链式方法?
编辑 我只记得这也可以通过对任何需要的人使用 $this->func->__invoke() 来完成。
【问题讨论】: