Why is the usage of $this in PHP necessary when referencing methods or variables in the same class?

后端 未结 5 1980
你的背包
你的背包 2021-01-16 04:24

I was explaining to a Java developer why his method call wasn\'t working. He just needed to add $this->method_name();

He then asked me, \"Why do

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 04:48

    $this refers to the calling object. The PHP docs have good examples and further details.

提交回复
热议问题