Difference between $this and self?

Inside a class definition, $this refers to the current object, while self refers to the current class.

It is necessary to refer to a class element using self, and refer to an object element using $this.

self::STAT // refer to a constant like this
self::$stat // static variable
$this->stat // refer to an object variable like this

Permanent link to this article: https://blog.openshell.in/2011/04/difference-between-this-and-self/

Leave a Reply

Your email address will not be published.