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" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to