【发布时间】:2015-01-30 13:09:57
【问题描述】:
是否可以知道方法调用是否来自方法链接?
比如我有下面class:
class Test{
protected $string = '123';
public function a($string){
$this->string .= $string;
if(method chain){
return $this;
}else{
return $this->string;
}
}
public function b($string){
$this->string .= $string;
if(method chain){
return $this;
}else{
return $this->string;
}
}
}
结果:
$test = new Test();
echo $test->a('000'); // 123000
echo $test->a('000')->b('www'); // 123000www
更新
我最终创建了一个 exec() 方法来告诉不再调用任何方法。
public function exec(){
return $this->string;
}
【问题讨论】:
标签: php method-chaining