/ Published in: PHP
Not extensively tested but should work just fine!
Expand |
Embed | Plain Text
<?php /** * Singleton object. Usage: * $objInstance = Singleton::getInstance('ClassName'); */ class Singleton { private function __construct() { } public function getInstance($strClassName) { self::$arrInstances[$strClassNameKey] = new $strClassName; } return self::$arrInstances[$strClassNameKey]; } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

It should be:
public STATIC function getInstance ($strClassName) { ... }
(Capitalization just to emphasize my fix).
Note; you can also define the class as abstract, and then not need to have a private __construct().