$this
is a reference to the current object.
It can be used in class methods only.
From the manual:
The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).
a simple real world example:
class Classname
{
var $message = "The big brown fox... jumped....";
function showMessage()
{
echo $this->message; // Will output whatever value
// the object's message variable was set to
}
}
$my_object = new Classname(); // this is a valid object
$my_object->name = "Hello World!";
$my_object->showMessage(); // Will output "Hello world"
$this
is not available when you call a method in a static context:
Classname::showMessage(); // Will throw an error:
// `$this` used while not in object context