複製代碼 代碼如下:
/**
* 單例模式
*
* 確保一個類別只有一個實例,並提供一個存取它的全域存取點
*
*/
class Singleton
{
static private $_instance = null;
tion getInstance( )
{
if(is_null(self::$_instance)) {
self::$_instance = new Singleton();
}
return self::unc$_instance;
}
return self::unc$_instance; echo "it is a singlton class function";
}
}
// $obj = new Singleton(); // 宣告不能成功
$obj = Sing $obj->display();
$obj1 = Singleton::getInstance();
var_dump(($obj === $obj1));