What is the difference between $this and self? When should we use each of them?
Asked
Active
Viewed 1,179 times
-4
elixenide
- 43,445
- 14
- 72
- 97
Shrikant D
- 747
- 1
- 7
- 14
2 Answers
4
$this refers to the current instance. self refers to the current class.
In other words, you can use $this->someMember to refer to an instance member and self::$someStaticMember to refer to a static member.
Mureinik
- 277,661
- 50
- 283
- 320