您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php单例模式的原理及实现方法

2024/5/30 4:56:13发布38次查看
这篇文章主要介绍了php单例模式,实例分析了单例模式的原理与实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了php单例模式实现方法。具体如下:
<?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中is_file()函数的定义与使用方法
php时间戳和时区的概念
php date函数简述及获取制定时间的方法
以上就是php单例模式的原理及实现方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product