self類本身

<?php 
//self類本身

class Ad{
	public $rand;
	static public $ob=null;
	final protected function __construct(){
		$this->rand=mt_rand(1000000000,99999999999);
	}

	static public function getins(){
		//對外開放一個接口
		if (self::$ob===null){
			//讓其對象只new一次
			self::$ob=new self();
		}
		return  self::$ob;
	}

}

var_dump(Ad::getins());





 ?>

發佈了47 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章