Source Code : Singleton Pattern Demo
PHP Is Open Source Programming Language You Can Download and use It, You required xampp server and wamp server . You download From xampp server from https://www.apachefriends.org/download.html.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://php.net/.
Click Here or search from google with Libraries Name you get jar file related it and also http://php.net/ is a official site
Singleton Pattern Demo
<?php
class Configuration {
static private $instance = NULL;
private $settingsArray;
private function __construct(){
}
public function __destruct() {
if(!$this->updated) {
return;
}
foreach ($this->settingsArray as $key => $value) {
echo("$key = "$value"
");
}
}
public function getInstance() {
if(self::$instance == NULL) {
self::$instance = new Configuration();
}
return self::$instance;
}
public function get($name) {
if(isset($this->settingsArray[$name])) {
return $this->settingsArray[$name];
} else {
return(NULL);
}
}
public function set($name, $value) {
if(!isset($this->settingsArray[$name]) OR ($this->settingsArray[$name] != $value)) {
$this->settingsArray[$name] = $value;
$this->updated = TRUE;
}
}
}
$config = Configuration::getInstance();
$config->set("username", "A");
$config->set("password", "B");
print($config->get("username"));
?>
Thank with us