<? 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.