What is a single case, and what is its role?
The singleton pattern is understood from the name. Single is once. The example is to instantiate an object, that is, I don't care how many times I use it to instantiate an object. OK, what is the function of this design pattern?
The singleton mode can ensure that there is only one instance of a class in the system, and the instance is easy to be accessed by the outside world, thus it is convenient to control the number of instances and save system resources.
For example, we're going to write a class that operates on MySQL. Connect to the database operation in the construction method. This class is used every new time if it is the usual notation. We've created a database connection here. For example, I have 100 files on my side that are called to this class at the same time. Every time you declare this MySQL class, you have to connect to the database. It's a pretty big expense. In order to solve this problem. A singleton pattern was born.
Singleton mode ">
The above introduces the PHP design mode singleton mode, including the design mode, the content of the singleton mode, I hope that the PHP tutorial interested in a friend helpful.