Re: :: context access (bug?)
| From: | Andi Gutmans | Date: | Thu, 04 Dec 2003 23:15:57 +0000 |
| Subject: | Re: :: context access (bug?) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-6233@lists.php.net to get a copy of this message | ||
This is a "feature". We decided to keep it the way it is, and have people who really want to code correctly define their static methods as static.
So to fix this you should define Miew() as static and you won't have access to the calling scope.
Andi
At 11:56 AM 12/4/2003 -0800, Marc Dembogurski wrote:
I´ve found the example below which took my attention. The call to cCat::Miew() assumes the cDog context and is able to access $this of cDog. Is this supposed to be a bug or something that was not expected ????? It happens to PHP4 to and php5. And looks a bit strange... class cCat { function Miew(){// cCat does not have a member "kind", but cDoghas, and we'll use itecho "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 { public $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! __________________________________ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php