The following is the code for the basic registry class:
Copy Code code as follows:
<?php
Class Registry {
private static $instance;
private $request;//content class for the registry
Private Function __construct () {}//This class, not instantiated
static function instance () {//Single example class, this method returns the instance
if (!isset (self:: $instance)) {self:: $instance =new self ();}
Return self:: $instance;
}
function Getrequest () {//returns the registered content class
return $this->request;
}
function setrequest (Request $request) {//Set registered content class
$this->request= $request;
}
}
Class request{//Registered Classes
Private $webname = "web Development notes";
Private $url = "www.chhua.com";
function GetName () {
echo $this->url;//Output www.chhua.com
}
}//Registered Empty Class
Use
$reg =registry::instance ();
$reg->setrequest (new request ());
$request = $reg->getrequest ();
$request->getname ();//Output www.chhua.com
?>
The function of the registry is to provide system-level object access.