本文实例讲述了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单例模式的原理及实现方法的详细内容。
