You are here: static member of a class and inheritance « PHP Programming Language « IT news, forums, messages
static member of a class and inheritance

Posted by giacomo.galilei on 09/25/06 16: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;
}
}
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 ?

Thanks in advance
Bye

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация