PHP design mode registry Mode _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.