Hi,
I'm struggling to create a singleton (i.e. following the proper design pattern for a singleton). My singleton is as follows:
class PlannerService {
private $my_variable;
private $my_other_variable;
private static $instance;
private function __construct() {
$this->my_variable = time();
$this->my_variable = time();
}
public static function getInstance() {
if ($instance == null) {
$instance = new PlannerService();
}
return $instance;
}
public function getMyVariable() {
return $this->my_variable;
}
public function getMyOtherVariable() {
return $this->my_other_variable;
}
}
When i then call this from my controller as below, every time i call it, it thinks that $instance is null and creates a new object.
$instance = PlannerService::getInstance();
$instance->getMyVariable();
Any ideas?