We all know the PHP Singleton mode, but seldom talk about the multi-sample mode of PHP. The following is an example of the multi-sample mode of PHP seen on wikipedia. Learning java, we know that there are multiple sample modes 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 ?>