2

I'm trying to improve my OOP skill. Recently, I've read an article that has this code structure:

$this->getUserInfo()->display();

When I code, I just do something like this:

$this->getUserInfo();

How do I do something like the above..."multiple-passing" or whatever it's called. I think it's cool if I can make my code be able to do that...just looking at the code...I'm impressed.

Can somebody post a code something replicating the above...I want to try it too. I want to learn how^^

Thanks!

5
  • 1
    Duplicate: stackoverflow.com/questions/3298707/… Commented Nov 13, 2010 at 1:37
  • oh so the term is mutiple oop...a! Thanks Tim! Commented Nov 13, 2010 at 1:38
  • 4
    No, the term is "method chaining". Commented Nov 13, 2010 at 1:40
  • 1
    Also known as "fluent interface" (but that has multiple meanings, and "method chaining" is technically more correct). Commented Nov 13, 2010 at 1:47
  • Yep...it's much more easier to learn if you know what it's called in the first place. Google is just around the corner :D Thanks GUYS! Commented Nov 13, 2010 at 1:53

2 Answers 2

5

The trick is to simply return an object from the getUserInfo() method, often the method returns the object it belongs to, i.e. $this.

function getUserInfo() {
    // do something
    return $this;
}
Sign up to request clarification or add additional context in comments.

Comments

0

if you want know more i suggest that know more about design pattern in OOP consept from Design pattern in simple examples

Comments

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.