When would you use the $this keyword in PHP?

前端 未结 12 1742
长发绾君心
长发绾君心 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:43

    The use $this is to reference methods or instance variables belonging to the current object

    $this->name = $name or $this->callSomeMethod()

    that is going to use the variable or method implemented in the current object subclassed or not.

    If you would like to specifically call an implementation of of the parent class you would do something like

    parent::callSomeMethod()

提交回复
热议问题