class Super
{
function Func()
{
echo "Super Func<br>";
$this->Func2();
}
function Func2()
{
echo "Super Func 2<br>";
}
// singleton
static private $instances = array(); // assoc array with one single instance for every class
static protected function getInstance($c=__CLASS__) // overload in subclasses (as public)
{
if(is_null(self::$instance[$c])) {
self::$instance[$c] = new $c();
}
return self::$instance[$c];
}
}
class Sub extends Super
{
function Func()
{
echo "Sub Func<br>";
parent::Func();
}
static public function getInstance($c=__CLASS__)
{
return parent::getInstance($c);
}
function Func2()
{
echo "Sub Func 2<br>";
parent::Func2();
}
}