Heya, Smartic.
You're probably talking about chaining (which falls under a programming style known as
Fluent Interface).
When you want to implement chaining, you simply need to make sure that each method call returns a reference to its parent instance by using the $this keyword:
-
class Foo
-
{
-
public function bar( )
-
{
-
return $this;
-
}
-
-
public function baz( )
-
{
-
return $this;
-
}
-
}
-
-
$Foo = new Foo();
-
$Foo->bar()->baz();
-
PHP does not allow you to chain off of the constructor, so you have to initialize (in this case) the Foo instance in a separate statement.
Note that $Foo->bar() returns a reference to $Foo, which allows you to chain the subsequent call to baz(). It would be equivalent to writing this:
-
$Foo = new Foo();
-
$Foo->bar();
-
$Foo->baz();
-