经典设计模式,主要考察对类的一些应用,有问题或更好的idea欢迎随时交流~
// 禁止外部new调用,使用私有构造函数,调用静态方法,
class single{
static private $instant = null;
private function __construct() {
}
public static function getInstant(){
if (self::$instant == null){
self::$instant = new self();
}
return self::$instant;
}
}
$obj = single::getInstant();