<?php
/*
* A true singleton in PHP
* @author Sourav Ray
* @version 1.0.0
* @name singletone.class
*/
class sTonClass
{
var $obj=array();
static $TheInstance;
private function sTonClass() // The constructor of the class is decleared as private
{ } // so no it is not possible to create an instance of the
// sTonClass outside the class.
public static function inisiate() //Statice function that creats the instance of the class.
{
if (sTonClass::$TheInstance==NULL) //Create a new object of sTonClass when there is
{ // no previous instace present.
sTonClass::$TheInstance = new sTonClass();
}
$instanceReferance =& sTonClass::$TheInstance; // If there is already an instance exists then return
return $instanceReferance; // the referance of the old Instance.
}
public function get($key)
{
return $this->obj[$key];
}
public function put($key,$object)
{
if ($this->obj[$key]==NULL)
$this->obj[$key]=$object;
}
public function invalidate($key)
{
unset($this->obj[$key]);
return (isset($this->obj[$key]));
}
} // End of Class sTonClass
?>