Re: PHP5 and static attributes

From: Date: Wed, 12 May 2004 11:56:16 +0000
Subject: Re: PHP5 and static attributes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185978@lists.php.net to get a copy of this message
Do you have to access that variable statically? If you're scope is the class: echo $this->myInstance; Otherwise, echo C::$myInstance will access it outside the class (I think), even though it's inherited. "Rudy Metzger" <rudy.metzger@pareto.nl> wrote in message news:1084352482.16920.45.camel@parlnx01.pareto.local... > Dear all, > > I have a problem with 'referencing' static attributes. I have the > following class tree. > > // --- CLASS A ----------------------------- > class A > { > protected static $myInstance; > } > > // --- CLASS B ------------------------------ > class B extends class A > { > } > > // --- CLASS C ------------------------------ > class C extends class B > { > > public function Debug() > { > echo self::$myInstance; // does not work (undefined) > echo parent::$myInstance; // also does not work > echo A::$myInstance; // works > } > > } > > ----------------------------------------- > The Problem is that you always have to know in which class the static > was defined to reference it. Or is there something like > static::$myInstance or this::$myInstance or class::$myInstance. If not, > it maybe would be a great idea to add something to PHP, otherwise you > always have to track in which class the static had been defined if you > want to reference it! > > Thanx for reading and if someone knows how to solve this, please let me > know! > > Cheerio > /rudy

« previous php.general (#185978) next »