class Singleton
{
/**
* @var array
*/
private static $instances = [];
/**
* Prevent direct instantiation.
*/
private function __construct()
{
}
/**
* Get the instance of this class.
*//self 当前函数所在类 static 当前调用的类名
* @return mixed */ final public static function getInstance() { $classname = get_called_class(); if (! isset(self::$instances[$classname])) { self::$instances[$classname] = new static(); } return self::$instances[$classname]; } /** * Prevent
cloning. * * @throws \RuntimeException */ final public function __clone() { throw new \RuntimeException('Clone is not allowed for ' . get_class($this)); } /** * Prevent unserialization. * * @throws \RuntimeException */ final public function __wakeup() { throw
new \RuntimeException('Unserialization is not allowed for ' . get_class($this)); }}
php单例模式
最新推荐文章于 2024-10-14 13:22:54 发布

303

被折叠的 条评论
为什么被折叠?



