Lets say i have the following code.
class A {
function one() {
return $this;
}
}
class B extends A {
function two() {
return $this;
}
}
Is there any way possible that i can method chain using a function from the parent class?
Such as..
$b = new B();
$b->one()->two();
Refer to this question for several responses that explain the meaning of the special variable
$this.In short, it refers to the current object. You’re creating an instance of
B, so even if you refer to$thiswithinfunction one()you’re still referring to the enclosing instance.