Code: Select all
<?php
class X
{
protected static $m;
public function println()
{
echo self::$m;
echo "\n";
}
}
class B extends X
{
public function __construct()
{
parent::$m = 5;
}
}
class C extends X
{
public function __construct()
{
parent::$m = 6;
}
}
$b = new B();
$c = new C();
$b->println();
$c->println();
?>Is there any way for B's static variable to hold 5 and C's static to hold 6 ? Overriding static member in inherited class... ?
I need a static variable for all decendants of X, but require println() function to be in X.
Or, all I need is the opposite of parent - child. something that I can do as if a scope resolution operator for child exited (child::).
Code: Select all
class X
{
public function set($value)
{
child::$z = $value;
}
public function println()
{
echo child::$z;
echo "\n";
}
}
class B extends X
{
public static $z;
public function __construct()
{
parent::set(5);
}
}
class C extends X
{
public static $z;
public function __construct()
{
parent::set(6);
}
}Thanks