本文實例講述了php單例模式實現方法。具體如下:
<?php/** * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> *//** * 單例模式 * Class Single */html' target='_blank'>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單例模式的原理及實現方法的詳細內容,更多請關注 其它相關文章!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答