ReviewPHP design mode: Singleton mode-JackyYu

Source: Internet
Author: User
ReviewPHP design mode-Singleton mode-JackyYu Singleton mode:

1 class Single {2 private static $ _ instance; 3 4 private function _ construct () {5 // define method as private 6} 7 8 public function _ clone () {9 trigger_error ('Clone is not allow! ', E_USER_ERROR); 10} 11 12 public static function getInstance () {13 if (! (Self: $ _ instance instanceof self) {14 self: $ _ instance = new self; 15} 16 return self: $ _ instance; 17} 18 19 public function show () {20 phpinfo (); 21} 22} 23 $ single = Single: getInstance (); 24 $ single-> show ();

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.