Re: What is a class

From: Date: Sat, 27 Oct 2001 12:32:17 +0000
Subject: Re: What is a class
References: 1  Groups: php.doc php.general php.windows 
Request: Send a blank email to phpdoc+get-969338225@lists.php.net to get a copy of this message
Hello Jack, Saturday, October 27, 2001, 1:51:01 PM, you wrote: J> Dear all J> I'm fresh on PHP, there is a question which i don't understand , even i had J> read the book about PHP. J> There is a Class and object in PHP, but i don't quite understand what is J> that for. J> I had look at some of the Example in PHP.net and i know most of it, but J> there is a operator : J> $this->edible = $edible; J> What is the "$this -> " stand for? J> Could someone please tell me more??? J> Thx "$this" is object where the function (which uses "$this") is declared. Here is an example: class A { var $aaa = "foo"; var $bbb; function fff() { echo $aaa; //$aaa is a local variable } function ggg() { echo $this->aaa; //$aaa is a member of object of class A } function hhh($newval) { $aaa = $newval; } function iii($newval) { $this->aaa = $newval; } function jjj() { ggg(); } function kkk() { $this->ggg(); } } $obj = new A; //creating object (or instance) of class A echo $obj->aaa; //printing object member variable $aaa //foo $obj->fff(); //fff() prints its own local variable $aaa (no value) // $obj->ggg(); //ggg() prints object member $aaa //foo $obj->hhh("bla"); //hhh() changes local variable's value to "bla" echo $obj->aaa; //foo $obj->iii("bla"); //iii() changes object member's value to "bla" echo $obj->aaa; //bla $obj->jjj(); //jjj() tries to call function ggg() that doesn't exists //!!!error!!! $obj->kkk(); //kkk() tries to call object member function ggg() //bla -- Best regards, Olexandr mailto:supaboy@i.com.ua

« previous php.doc (#969338225) next »