《PHP編程:php單例模式實現(xiàn)方法分析》要點:
本文介紹了PHP編程:php單例模式實現(xiàn)方法分析,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP應(yīng)用本文實例講述了php單例模式實現(xiàn)辦法.分享給大家供大家參考.具體如下:
PHP應(yīng)用
<?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應(yīng)用希望本文所述對大家的php程序設(shè)計有所贊助.
《PHP編程:php單例模式實現(xiàn)方法分析》是否對您有啟發(fā),歡迎查看更多與《PHP編程:php單例模式實現(xiàn)方法分析》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/11731.html