The singleton pattern (Singleton pattern) is a creation pattern that restricts the application to create only a single instance of a class type. For example, a Web site will need a database connection object, but there should be only one, so we need to use Singleton mode to implement.
eg
<?PHPclassconfig{Static Private $_instance=NULL;//ensure that there is only one single instance for a particular class Private $_settings=Array(); Private function__construct () {}//prevent new instances from coming out Private function__clone () {}//prevent clone from creating a new instance Staticfuncitn getinstance () {if(Self::$_instance==NULL) { self::$_instance=NewConfig (); } returnSelf::$_instance; } functionSet$index,$value){ $this->_settings[$index] =$value; } functionGet$index){ return $this->_settings[$index]; }}?>
Using the Config class
Creating the Config Class
$CONFIG = Config::getinstance ();
If this object is the first object of the class, a new instance of the class is created, assigned to the internal private property $_instance, and the result is returned. Otherwise, use the same instance to return