Single-instance Implementation of PHP design patterns

Source: Internet
Author: User
<? PHP  Class  A {  Static   Public   $ OBJ  ;  Public   Function  _ Construct (){}  Static   Public   Function  Getinstance (){  If ( Empty (SELF :: $ OBJ  )){  Echo "Execute instantiation" ; Self :: $ OBJ = New  A ();}  Return SELF :: $ OBJ  ;}  Public   Function  Test (){  Return "111";}}  $ Newinstance = :: Getinstance ();  Echo   $ Newinstance -> Test ();  $ Newinstance1 = :: Getinstance ();  Echo   $ Newinstance1 -> Test (); ?>

A few days ago, I heard a PHP predecessor from Baidu say that if you want to learn the source code of the system, you need to understand the design pattern so that you can quickly read the excellent source code.
So I want to try to implement all the design patterns, and I will be able to get twice the result with half the effort in the future.

PHP Singleton mode with no technical skills. The main purpose is to use the singleton mode to reduce system overhead when the page may call the same instance more.

the most common type is dB. Almost all PHP frameworks use this routine.

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.