Re: newbie question about $this

From: Date: Sun, 06 Aug 2000 16:03:24 +0000
Subject: Re: newbie question about $this
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10334@lists.php.net to get a copy of this message
David Banning wrote: > > I am just a newbie studying php - I am looking at code and notice > variables > like $this->Name - the documentation I have makes no mention of $this > (pun accidental). > > Is $this a variable? If so where is it set? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net Hi David, $this is a variable which points to the class you are in. Or more exactly: It points to the actual instance of the class you are in. Example: class A { var $test; function SetTest() { $this->test = "Something"; } } So, if you now call: $myClass = new A(); $myClass->SetTest(); # Now in "SetTest" $this = $myClass; $anotherClass = new A(); $anotherClass->SetTest(); # Now in "SetTest" $this = $anotherClass; Regards Martin

« previous php.general (#10334) next »