close
:: 用來宣告使用於 static 的變數或方法
而
->是用於一般非 static 的變數與方法
範例參考自其他網站(感謝)
例如:
class DB
{
private static $_instance = null;
private static $_instanceCount = 0;
private function __construct()
{
self::$_instanceCount ++;
}
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
public function getInstanceCount()
{
return self::$_instanceCount;
}
}
$db1 = DB::getInstance();
echo $db1->getInstanceCount(), "\n"; // 1
$db2 = DB::getInstance();
echo $db2->getInstanceCount(), "\n"; // 1
全站熱搜
留言列表