0

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!!

2
  • I don't think you can do that within PHP. Why would you need to? Commented Nov 11, 2013 at 2:15
  • if that is not possible, that is fine. Commented Nov 11, 2013 at 2:16

1 Answer 1

2

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'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I just want to know if its possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.