Reputation: 4550
I dont know how to explain this question so maybe the tile is not matched.
Class a {
function b{
return $this;
}
function c{
return $this;
}
}
If I have class structure like this I can do
$a = new a();
$a->b()->c();
I want to know how can I know the function is not continued like $a->b();
, then I return $retuslt instead of $this.
Class a {
function b{
//if not continued
return $result;
//if continued
return $this;
}
function c{
return $this;
}
}
Is this possible? thank you very much!!
Upvotes: 0
Views: 158
Reputation: 141
It is not possible. You will not know inside the method what is being done with the return. You could however pass a return value in, for example:
Class a {
function b(&$return){
// do something
$return = 'some value';
return $this;
}
function c(){
return $this;
}
}
$a = new a();
$a->b($returnFromB)->c();
echo $returnFromB; // 'some value'
Upvotes: 2