Re: PHP5 and static attributes

From: Date: Wed, 12 May 2004 14:29:13 +0000
Subject: Re: PHP5 and static attributes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185997@lists.php.net to get a copy of this message
* Thus wrote Rudy Metzger (rudy.metzger@pareto.nl): > 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! What version of php are you using? It appears to work with RC1 to CVS version. The actual result I get is: public function Debug() { echo self::$myInstance; // works echo parent::$myInstance; // error: Cannot access protected property echo A::$myInstance; // error: Cannot access protected property } Its expected for the errors on the last two since you're accessing the protected variable from outsite the public scope of Debug(). Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#185997) next »