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:[EMAIL PROTECTED]



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to