php单例模式
来源:互联网 发布:现实爆炸录像软件 编辑:程序博客网 时间:2024/05/19 06:51
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)); }}
阅读全文
0 0
- php单例模式
- php单例模式
- PHP单例模式
- PHP单例模式
- PHP单例模式
- php 单例模式
- php单例模式
- PHP 单例模式
- PHP 单例模式
- php 单例模式
- php单例模式
- PHP单例模式
- php单例模式
- php单例模式
- PHP单例模式
- php单例模式
- php单例模式
- PHP单例模式
- [每日问答]生成方法和判别方法有什么区别?
- 树学习(2)
- 收藏超长版
- ffmpeg参数中文详细解释
- Linux下的SVN服务器搭建
- php单例模式
- 一些关于kafka的笔记
- 自动化测试工具AutoRunner之录制脚本(二)
- 主题错误
- 原码、反码、补码
- 收藏超长版(2)
- 使用 xpath 定位包含指定文本内容的标签
- Ubuntu下搭建VPN服务器
- 3263 丽娃河的狼人传说