<?php
class test{
protected function __construct(){
}
public static function getInstance(){
static $_test;
if (empty($_test)) {
$_test = new test();
}
return $_test;
}
}
为什么在单例模式中该类要有一个public static的方法,而其他的方法都不能用public方法。这样做的目的是什么
简单的说,就是不让再次初始化了,也没有这个必要,保证就一个实例。需要什么方法,你调用得到的实例中的public方法啊。