I'm a beginner and having trouble understanding the -> syntax in php, i know that it is used to access object in a class, but what does it mean if i you put multiple ->, for example:
$this -> $var1 -> var2 -> var3
I'm a beginner and having trouble understanding the -> syntax in php, i know that it is used to access object in a class, but what does it mean if i you put multiple ->, for example:
$this -> $var1 -> var2 -> var3
It's the same as accessing nested arrays using this:
$arr['key1']['key2']['key3']
(I hope this analogy is helpful to you.)
$this->var1->var2->var3
Here $this
is an object which has a property var1
. var1
is also an object itself which has a property var2
. var2
is also an object itself which has a property var3
. It could be constructed as such:
$this->var1 = new stdClass;
$this->var1->var2 = new stdClass;
$this->var1->var2->var3 = new stdClass;