Copy CodeThe code is as follows:
/**
* Single case mode
*
* Ensure that a class has only one instance and provides a global access point to access it
*
*/
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 (); Declaration cannot succeed
$obj = Singleton::getinstance ();
Var_dump ($obj);
$obj->display ();
$obj 1 = singleton::getinstance ();
Var_dump (($obj = = = $obj 1));
http://www.bkjia.com/PHPjc/323802.html www.bkjia.com true http://www.bkjia.com/PHPjc/323802.html techarticle Copy the code as follows:? PHP/** * Singleton mode * Ensures that a class has only one instance and provides a global access point to access it * */class Singleton {static private $_instance ...