设计模式之单例模式
<?php
class Single
{
protected $rnd;
protected static $ins =null ;
//将自动加载 设置为 protected类型
//这样没法new 类名进行实例化
protected function __construct() {
$this->rnd =rand(0,1000);
}
//声明一个静态方法
public static function getins(){
//判断self::$ins 保存着实例化之后的对象
if (self::$ins == null) {
self::$ins = new self();
}
return self::$ins;
}
}
?>