When to use self over $this?

前端 未结 23 3237
醉梦人生
醉梦人生 2020-11-21 11:19

In PHP 5, what is the difference between using self and $this?

When is each appropriate?

23条回答
  •  庸人自扰
    2020-11-21 11:58

    According to php.net there are three special keywords in this context: self, parent and static. They are used to access properties or methods from inside the class definition.

    $this, on the other hand, is used to call an instance and methods of any class as long as that class is accessible.

提交回复
热议问题