本文实例讲述了php单例模式实现方法。分享给大家供大家参考。具体如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39<?php /** * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> */ /** * 单例模式 * Class Single */ class Single { private $name; private static $single; private function __construct() { } public static function init() { if(empty(self::$single)) { self::$single = new Single(); } return self::$single; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } } $s = Single::init(); $s->setName('hhhh'); echo '$s:'.$s->getName(); unset($s); $m = Single::init(); echo '$m:'.$m->getName();
希望本文所述对大家的php程序设计有所帮助。
最后
以上就是舒服流沙最近收集整理的关于php单例模式实现方法分析的全部内容,更多相关php单例模式实现方法分析内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复