-4

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

elixenide
  • 44,308
  • 16
  • 74
  • 100
Shrikant D
  • 807
  • 1
  • 8
  • 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
  • 297,002
  • 52
  • 306
  • 350
0

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

Sagar
  • 642
  • 3
  • 14