When would you use the $this keyword in PHP?

前端 未结 12 1744
长发绾君心
长发绾君心 2020-12-15 11:03

When would you use the $this keyword in PHP? From what I understand $this refers to the object created without knowing the objects name.

Al

12条回答
  •  生来不讨喜
    2020-12-15 11:46

    Used for when you want to work with local variables.

    You can also read more about it from here.

    function bark() {
        print "{$this->Name} says Woof!\n";
    }
    

提交回复
热议问题