How can I have a class which allows me to have a another variable when calling,
eg.
$class->variable1->variable2->function();
How can I have a class which allows me to have a another variable when calling,
eg.
$class->variable1->variable2->function();
If you wanted say $class->function1()->function2()->function3()
, you would need to return $this
at the end of your function logic.
As for $class->var->var->func()
you would need to have the $class->var->var
as a new instance of the class the function belongs to.
This is what you think of:
class OtherClass {
public function something() {
return "foo";
}
}
class Test {
public $variable;
public function Test() {
$this->variable = new OtherClass();
}
}
$foo = new Test();
echo $foo->variable->something();
But if you want that kind of method chaining is questionable. You probably want to look into http://php.net/oop for a complete reference on Object Oriented Programming with PHP.