php 디자인 모드 Singleton(단일 모드)

855 단어
 
  
/**
*
*
* ,
*
*/
class Singleton
{
static private $_instance = null;

private function __construct()
{
}

static public function getInstance()
{
if(is_null(self::$_instance)) {
self::$_instance = new Singleton();
}
return self::$_instance;
}

public function display()
{
echo "it is a singlton class function";
}
}

// $obj = new Singleton(); //
$obj = Singleton::getInstance();
var_dump($obj);
$obj->display();

$obj1 = Singleton::getInstance();
var_dump(($obj === $obj1));

좋은 웹페이지 즐겨찾기