0

Possible Duplicate:
What does the variable $this mean in PHP?

I see a lot of $this in php and oop programming. What is it?

Community
  • 1
  • 1
tee
  • 155
  • 2
  • 6
  • 12
  • 3
    Duplicate of [What does the variable $this mean in PHP?](http://stackoverflow.com/questions/1523479/what-does-the-variable-this-mean-in-php) and many others. – deceze Jan 13 '11 at 03:29
  • 3
    Can you please go back through your old questions and accept the answers of those who took the time to assist you? This community strives on helping others and giving credit to those that lend their time. – Brad Christie Jan 13 '11 at 03:34

4 Answers4

2

When used in a class, $this refers to the class instance. You need to use it to access class members (not global, or local -- their scope is confined to the class).

mpen
  • 272,448
  • 266
  • 850
  • 1,236
1

refers to the object it is referenced within. so if your object's class has a method called blah(), in another method in that class you might use $this->blah() to call the other method.

dqhendricks
  • 19,030
  • 11
  • 50
  • 83
1

It refers to the current instance of the class you are in

Robokop
  • 906
  • 1
  • 5
  • 12
1

$this refers to the active class and is used to access methods and properties within the active class. Likewise you can use self for static methods and properties.

I suggest you give this a read > http://www.php.net/manual/en/language.oop5.basic.php

Naatan
  • 3,424
  • 4
  • 32
  • 51