note 54843 added to language.oop5.patterns
| From: | lukas dot starecek at centrum dot cz | Date: | Sun, 17 Jul 2005 08:12:44 +0000 |
| Subject: | note 54843 added to language.oop5.patterns | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92072@lists.php.net to get a copy of this message | ||
If you need singleton of any class and don't want write singleton wrapper for each this class,
try this:
class UniverzalSingleton {
const EXCEPTION_NO_CLASS = 1;
protected static $_instances = array();
public static function getInstance($class) {
if (!isset(self::$_instances[$class])) {
if (!class_exists($class))
throw (new Exception(__CLASS__ . ': Requsted class is not exist.',
self::EXCEPTION_NO_CLASS));
self::$_instances[$class] = new $class();
} // if
return self::$_instances[$class];
} // getInstance
} // class UniverzalSingleton
----
Manual Page -- http://www.php.net/manual/en/language.oop5.patterns.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54843
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54843&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54843&report=yes
Search -- http://master.php.net/manage/user-notes.php