I ahve a singleton pdo databasr class that works just fine.
What I was wondering was can that class inherit from a non-static parent?
class myParent {
static protected $var1;
protected $var2;
public function __construct($input1) {
$this->var1 = $input1;
}
public function to_inherit() {
// do something
return $this->var2;
}
}
class singletonChild extends myParent {
private static $instance ;
private function __construct($input1)
parent::__construct($input1);
}
public static function getInstance($input1) {
if(!isset(self::instance)) {
self::instance = new singletonChild($input1);
}
return self::instance;
}
}
$test = singletonChild::getInstance($input1);
$result = $test->toInherit();
// which should return $var2 from the parent: or not as the case may be
Any thoughts?