overwritting parent static variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moger777
Forum Newbie
Posts: 2
Joined: Sun Nov 09, 2008 8:04 pm

overwritting parent static variables

Post by moger777 »

I was wondering if I can do something like

Code: Select all

 
class A{
 
    function hello(){
       prints(self::$value);
    }
}
 
class B extends A{
   static $value = "something";
}
 
class C extends A{
   static $value = "something else";
}
 
B::hello(); //want this to print "something";
C::hello(); //want this to print "something else";
 
 
I am a complete php newb and would greatly appreciate any help. For the purposes of the program I am writing I can also make $value a constant as long as they are class values and not instance values.
moger777
Forum Newbie
Posts: 2
Joined: Sun Nov 09, 2008 8:04 pm

Re: overwritting parent static variables

Post by moger777 »

bump
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: overwritting parent static variables

Post by Mark Baker »

Code: Select all

 
B::hello(); //want this to print "something";
C::hello(); //want this to print "something else";
 
You'll need to wait for PHP 6 which uses late static binding with the static keyword, when you'll be able to use print(static::$value);
Post Reply