The following is the code for the basic registry class:
Copy CodeThe code is as follows:
Class Registry {
private static $instance;
private $request;//The contents class of the Registry
Private Function __construct () {}//This class, not instantiated
static function instance () {//Singleton class, which returns an instance by this method
if (!isset (self:: $instance)) {self:: $instance =new self ();}
Return self:: $instance;
}
function Getrequest () {//Return the Registered content class
return $this->request;
}
function setrequest (Request $request) {//Set the registered content class
$this->request= $request;
}
}
Class request{//Registered Classes
Private $webname = "web Development note";
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 purpose of the registry is to provide system-level object access functionality.
http://www.bkjia.com/PHPjc/325015.html www.bkjia.com true http://www.bkjia.com/PHPjc/325015.html techarticle here is the code for the basic registry class: Copy Code as follows: PHP class Registry {private static $instance; private $request;//registry content class Private function __con ...