PHP Newsletter

Join now and receive weekly updates pertianing to the world of PHP.

Polls

What do you think about the new PHPMine Design?
Awesome
Not Bad
Sucks

PHP Gigs By City

PHP Jobs By Topic

Advertisements

PHP Question, what does $this do?

Asked 2010-03-07 10:50:39 by Smith

For example

<?php
class my_class
{
var $my_var;

function my_class ($var)
{
global $obj_instance;

$obj_instance = $this;
$this->my_var = $var;
}

}

$obj = new my_class ("something");
echo $obj->my_var;
echo $obj_instance->my_var;

?>

What is $this doing?

Anwered 2010-03-07 10:57:31 by jimbot

$this refers to the instance of the object in which it is currently operating.

In the case of your example, $this refers to the object contained in the global variable $obj.

Questions and answers provided by the Yahoo Answers Community.