Is this the right way if I want properly write a Singleton class so that a maximum of one SingleClass object exists.
<?php
class SingleClass
{
static $object;
static public function getSingleton()
{
if(!isset(self::$object))
{
self::$object = new SingleClass();
}
return self::$object;
}
private function __construct()
{
}
}
$mySingle1 = SingleClass::getSingleton(); // one object made
$mySingle2 = SingleClass::getSingleton(); // reference to first object returned
$mySingle3 = SingleClass::getSingleton(); // reference to first object returned
?>
if this is how it's done how can I do a check on it with if/else functions?