Page 1 of 1

overwritting parent static variables

Posted: Sun Nov 09, 2008 8:11 pm
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.

Re: overwritting parent static variables

Posted: Mon Nov 10, 2008 9:39 am
by moger777
bump

Re: overwritting parent static variables

Posted: Mon Nov 10, 2008 3:10 pm
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);