-4

What is the difference between $this and self? When should we use each of them?

elixenide
  • 43,445
  • 14
  • 72
  • 97
Shrikant D
  • 747
  • 1
  • 7
  • 14

2 Answers2

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
0

$this points to current object where as self:: points to current class.

Sagar
  • 632
  • 3
  • 14