国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php4和php5單態(tài)模式(Singleton Pattern)寫法

2024-05-04 21:51:37
字體:
供稿:網(wǎng)友

單態(tài)模式(Singleton Pattern) 就是一個(gè)類Class只有一個(gè)實(shí)例存在。(Ensure a class only has one instance, and provide a global point of access to it.)
這個(gè)是php5的寫法。

以下為引用的內(nèi)容:
<?php
class SingletonPhp5{
static private $_instance=null;

function getInstance(){
if(! self::$_instance){
self::$_instance=new self;
}
return self::$_instance;
}

function __construct(){

}

function Show(){
echo 'Singleton on Php5';
}
}

{
$Singleton=SingletonPhp5::getInstance()->Show();
}

這個(gè)是php4的寫法,當(dāng)然此方法在php5下也可以正常運(yùn)行。

以下為引用的內(nèi)容:

class SingletonPhp4{
function &getInstance(){
static $_instance=array();
if(empty($_instance)){
$_instance[]= & new SingletonPhp4();

}
return $_instance[0];

}

function SingletonPhp4(){

}

function Show(){
echo 'Singleton on Php4';
}
}

{
$Singleton=SingletonPhp4::getInstance();
$Singleton->Show();
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 和平区| 桐乡市| 凯里市| 河西区| 宁河县| 嘉义县| 南靖县| 澄江县| 驻马店市| 饶河县| 湖口县| 邵阳市| 兴安盟| 洪洞县| 图木舒克市| 邳州市| 水富县| 安国市| 靖安县| 阳西县| 杭锦后旗| 洛隆县| 霍州市| 塘沽区| 江源县| 慈溪市| 辽宁省| 肥西县| 莒南县| 土默特右旗| 贡山| 杂多县| 河源市| 沂水县| 泾阳县| 芜湖市| 依安县| 彩票| 云林县| 秦安县| 浮梁县|