PHP multi-sample mode

Source: Internet
Author: User
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  ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.