When learning java, you will know that there are multiple examples in the design mode: 1. multiple examples can have multiple instances. 2. multiple examples must be able to create and manage their own instances, and provide external users with their own instances. We all know the single-sample PHP mode, but seldom say the multi-sample PHP mode. below is
When learning java, you will know that there are multiple examples in the design mode:
1. Multiple instance types can have multiple instances
2. you must be able to create and manage your own instances and provide your own instances to the outside world.
We all know the PHP Singleton mode, but seldom talk about the PHP Singleton mode. Below is an example of the PHP Singleton mode seen on wikipedia:
newInstanceArgs(func_get_args());}return self::$instances[$key]; }}class Hello extends Multiton {public function __construct($string = 'World') {echo "Hello $string\n";}}class GoodBye extends Multiton {public function __construct($string = 'my', $string2 = 'darling') {echo "Goodbye $string $string2\n";}}$a = Hello::getInstance('World');$b = Hello::getInstance('bob');// $a !== $b$c = Hello::getInstance('World');// $a === $c$d = GoodBye::getInstance();$e = GoodBye::getInstance();// $d === $e$f = GoodBye::getInstance('your');// $d !== $f ?>
We can see that the key value needs to be transferred by getInstance () in the PHP multi-sample mode. for a given key value, the PHP multi-sample mode only has a unique object instance, and the PHP multi-sample mode saves memory, make sure that multiple instances of the same object do not conflict.