The following is the code for the basic registry class:
Copy the code The code is as follows:
class Registry {
private static $instance;
private $request;//Content class of the registry
private function __construct(){}//This class cannot be instantiated
static function instance() {//Singleton class, return the instance through 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 class
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 role of the registry is to provide system-level objects Access features.
http://www.bkjia.com/PHPjc/325015.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325015.htmlTechArticleThe following is the code of the basic registry class: Copy the code as follows: ?php class Registry { private static $instance ; private $request;//The content class of the registry private function __con...