|
Posted by Oli Filth on 09/25/06 17:17
giacomo.galilei@gmail.com said the following on 25/09/2006 17:55:
> I have this piece of code:
>
>
> abstract class Kaos
> {
> static $foo;
> abstract function MyFunc();
> }
>
> ..
> $bar = "aaa";
> class Kronos extends Kaos
> {
> function MyFunc() {
> echo self::$foo;
> }
> }
> Kronos::$foo = $bar;
>
> ..
> $bar = "bbb";
> class Zeus extends Kronos
> {
> function MyFunc() {
> parent::MyFunc();
> echo self::foo;
^
^
Where is the $ sign here??
> }
> }
> Zeus::$foo = $bar;
>
>
> At this point i would like that this code to show "aaabbb", but it
> shows "bbb";
>
> $a = new Zeus();
> $a -> MyFunc();
>
> Why ? I think that i have misunderstood the meaning of 'static' keyword
> for a class member, but i need a field that has the same name in each
> class, but in the calls of Kronos (of a Zeus object) its value is "aaa"
> and in the calls of Zeus its value is "bbb".
> How can i do this ? Is possible ?
Not this way. There is only instance of $foo, contained as a static
member of Kaos. The behaviour you are getting is similar to that in C++
and Java.
You could have a separate static $foo declared in each class; however,
this too has limitations.
What exactly do you need this for? i.e. how are you using $foo? There
may be a more suitable solution to your problem.
--
Oli
Navigation:
[Reply to this message]
|