note 33055 added to keyword.paamayim-nekudotayim

From: Date: Sun, 15 Jun 2003 10:40:02 +0000
Subject: note 33055 added to keyword.paamayim-nekudotayim
Groups: php.notes 
Request: Send a blank email to php-notes+get-50369@lists.php.net to get a copy of this message
when using "::" operator inside class functions, you can achieve quite interesting results. let's take this example: class cCat { function Miew(){ // cCat does not have a member "kind", but cDog has, and we'll use it echo "I am ".$this->kind.", and I say MIEW\n"; // here things are even stranger: does cCat class // support WhoAmI function? guess again... $this->WhoAmI(); } } class cDog { var $kind = "DOG"; function Bark(){ // let's make this dog act like a cat:) cCat::Miew(); } function WhoAmI(){ echo "Yes, I'm really ".$this->kind."!"; } } $dog = new cDog(); echo $dog->Bark(); outputs: I am DOG, and I say MIEW Yes, I'm really DOG! The interesting thing here is that cDog is not descendant of cCat nor vice versa, but cCat was able to use cDog member variable and function. When calling cCat::Miew() function, your $this variable is passed to that function, remaining cDog instance! It looks like PHP doesn't check if some class is an ancestor of the class, calling function via '::'. ---- Manual Page -- http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33055 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33055&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33055&report=yes

« previous php.notes (#50369) next »