< span> < span> ' I am construceted '< span> (!(Self::=::= < span> self:: < span prevents users from replicating object instances Span> (' Clone is isn't allow ', < span> ("Test" < span> = = Example:: -> = < span> <> <> <>
First, we need to know the concept of a singleton pattern, so what is a singleton pattern?
The singleton pattern, as its name implies, is only one instance.
As the creation mode of an object, the singleton pattern ensures that a class has only one instance, and instantiates itself and provides this instance to the entire system.
This class is what we call a singleton class.
The main points of the singleton pattern are three:
< span="">
< span="">
< span="">
Let's discuss why we use PHP singleton mode.
Most people understand its purpose from the literal meaning of the singleton pattern, and think that it is a kind of "family planning" that saves the system resources and avoids duplication of instantiation. Each time PHP executes the page, it cleans up all the resources from memory. Thus, in PHP, the single instance of the actual operation needs to be re-instantiated, thus losing the meaning of a single case of repeated instantiation. In this respect alone, PHP's singleton is indeed a bit disappointing for you. But does the singleton only have this function and application? The answer is no, let's take a look.
1. PHP is mainly used in database applications, so there will be a large number of database operations in an application, in the use of object-oriented development (nonsense), if you use the singleton mode, you can avoid a large number of new operations to consume resources.
2. If a class is needed in the system to control some configuration information globally, it can be easily implemented using singleton mode. This can be see the Frontcontroller section of the Zend Framework.
3. In a page request, it is easy to debug, because all the code (such as database Operation class DB) is concentrated in a class, we can set the hooks in the class, output the log, so as to avoid var_dump everywhere, echo.
http://www.bkjia.com/PHPjc/440191.html www.bkjia.com true http://www.bkjia.com/PHPjc/440191.html techarticle ? ' I am construceted ' (! (self:: =:: = Self:: (' Clone was not allow ', ("test" = = Example::-=?) First of all, we need to know the concept of a single case pattern, then what is a singleton model ...