<?php
//Basic Class
class webSite {//A very simple basic class
private $siteName;
private $siteUrl;
function __construct($siteName,$siteUrl){
$this->siteName=$siteName;
$this->siteUrl=$siteUrl;
}
function getName(){
return $this->siteName;
}
function getUrl(){
return $this->siteUrl;
}
}
class registry {//Registration class singleton pattern
private static $instance;
private $values=array();//Storing class names with arrays
private function __construct(){}//This usage determines that this class cannot be instantiated directly
static function instance(){
if (!isset(self::$instance)){self::$instance=new self();}
return self::$instance;
}
function get($key){//Get registered class
if (isset($this->values[$key])){
return $this->values[$key];
}
return null;
}
function set($key,$value){//Register class method
$this->values[$key]=$value;
}
}
$reg=registry::instance();
$reg->set("website",new webSite("WEB development notes",""));//Register the class
$website=$reg->get("website");//Get class
echo $website->getName();//Output WEB development notes
echo $website->getUrl();//Output
?>