0

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
monkey coder
  • 153
  • 1
  • 1
  • 11

1 Answers1

2

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;
deceze
  • 510,633
  • 85
  • 743
  • 889
  • You may often use this in decoding JSON as well, [such as this](https://eval.in/private/2fff72e45e63d4). – Dave Chen Sep 04 '14 at 15:54