I've seen other objects that do this:
$obj->method1()->method2();
How do I do that? Is each function just modifying the pointer of an object or returning a pointer?
I don't know the proper term for this style -- if anyone could help me with that, it would be great.
This is achieved by returning $this at the end of each function, thus giving a chainable reference.
class MyClass {
public function method1() {
//...
return $this;
}
public function method2() {
//...
return $this;
}
}
Fluid interface.
Simply set your object's method1() to return $this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With