In PHP 5, what is the difference between using self
and $this
?
When is each appropriate?
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 value
self::$stat // static variable
$this->stat // refer to an object variable