PHP Single-instance mode

Source: Internet
Author: User

1<?PHP2 3 4 /*5 Design Patterns6 is an empirical summary of the code patterns in "Common tasks" in object-oriented programming. 7 It is not an object-oriented syntax, or concept. 8 corresponding to our previous "algorithm"--the idea of solving the problem. 9 Ten the so-called design pattern, is to solve some kind of problem code routines.  One Different problems, different routines, also constitute a different design pattern.  A  - There are a number of design patterns.  -  the  - single-case mode - in practical applications, some classes, which only need new "one object", are sufficient to accomplish the design goal of the class-to accomplish a specific task.  - Then: + if a class is designed so that the class "can only get a corresponding object", then this class, called "Singleton Class", its new object is called "Singleton object".  -  +  A  at */ -     //Design Patterns -     classS { -         Private Static $instance=NULL; -  -         //private constructs do not allow outside new objects in         Private function__construct () { -  to         } +  -         //declares a static method to provide the outside world with a static method that can only be used to derive an object from the          Public Static functiongetinstance () { *  $             if(Empty(Self::$instance)) {//determine if a static variable is nullPanax NotoginsengSelf::$instance=NewSelf (); -                 returnSelf::$instance;//new Object If the variable is null the}Else{ +  A                 returnSelf::$instance;  the  +             } -                      $         } $}

PHP Single-instance mode

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.