In PHP 5, what is the difference between using self
and $this
?
When is each appropriate?
I ran into the same question and the simple answer is:
$this
requires an instance of the classself::
doesn'tWhenever you are using static methods or static attributes and want to call them without having an object of the class instantiated you need to use self:
to call them, because $this
always requires on object to be created.