首页 > 编程 > PHP > 正文

php单例设计模式

2019-11-08 01:02:56
字体:
来源:转载
供稿:网友
单例模式:一是某个类只能有一个实例;二是它必须自行创建这个实例;

三是它必须自行向整个系统提供这个实例。

class test{ PRotected function __construct(){ } public static function getInstance() { static $test; if (empty($test)) { $test = new test(); } return $test; }$test1 = test::getInstance();}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表