//静态变量保存全局实例
private static $_instance = null;
//私有构造函数,防止外界实例化对象
private function __construct() {
}
//私有克隆函数,防止外届克隆对象
private function __clone() {
}
//静态方法,单例统一访问入口
static public function getInstance() {
if (is_null ( self::$_instance ) || isset ( self::$_instance )) {
self::$_instance = new self ();
}
return self::$_instance;
}
把上面代码copy到php类里面就可以了
使用静态变量
http://www.cnblogs.com/shangxia/p/6029728.html