Revision: 8366
Updated Code
at March 12, 2009 07:43 by DaveChild
Updated Code
<?php /** * Singleton object. Usage: * $objInstance = Singleton::getInstance('ClassName'); */ class Singleton { private static $arrInstances = array(); private function __construct() { } public function getInstance($strClassName) { $strClassNameKey = strtolower($strClassName); if (!array_key_exists($strClassNameKey, self::$arrInstances)) { self::$arrInstances[$strClassNameKey] = new $strClassName; } return self::$arrInstances[$strClassNameKey]; } } ?>
Revision: 8365
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 17, 2008 05:27 by DaveChild
Initial Code
<?php /** * Singleton object. Usage: * $objInstance = Singleton::getInstance('ClassName'); */ class Singleton { private static $arrInstances = array(); private function __construct() { } public function getInstance($strClassName) { $strClassNameKey = strtolower($strClassName); if (!array_key_exists($strClassNameKey, self::$arrInstances)) { self::$arrInstances[$strClassNameKey)] = new $strClassName; } return self::$arrInstances[$strClassNameKey]; } } ?>
Initial URL
Initial Description
Not extensively tested but should work just fine!
Initial Title
PHP Singleton Class
Initial Tags
Initial Language
PHP