Re: newbie question about $this
| From: | Ben-Nes Michael | Date: | Sun, 06 Aug 2000 16:30:41 +0000 |
| Subject: | Re: newbie question about $this | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10340@lists.php.net to get a copy of this message | ||
To learn more check for classes in the manual
And check all the newbie sites on Orient Objects / Class
Martin Thoma wrote:
> 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
>
> --
> 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
--
--------------------------
Canaan Surfing Ltd.
Internet Service Providers
Ben-Nes Michael - Manager
Tel: 972-6-6925757
Fax: 972-6-6925858
http://www.canaan.co.il
--------------------------