In PHP 5, what is the difference between using self
and $this
?
When is each appropriate?
$this
refers to the current class object, self
refers to the current class (Not object). The class is the blueprint of the object. So you define a class, but you construct objects.
So in other words, use self for static
and this for none-static members or methods
.
also in child/parent scenario self / parent
is mostly used to identified child and parent class members and methods.