All pastes #73794 Raw Edit

suv4x4

public text v1 · immutable
#73794 ·published 2006-06-28 08:44 UTC
rendered paste body
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();		
	}
}