PHP Single-instance mode

Source: Internet
Author: User

Single Case : Single instance. Design a class, there are only one object, this design pattern is called a singleton mode!

Role : A single case design, is applicable to the use of an object can complete all business logic of the class, so that a class as long as the instantiation can complete all the business logic, thereby saving resources space !

Class Mydemo {


Private static $instance;


Private Function __construct ($p 1) {

}


Public static function getinstance($p 1) {

if (! (Self:: $instance instanceof Self)) {

Not instantiated.

Self:: $instance = new self ($p 1);

}


Return self:: $instance;

}


Private Function __clone () {

}

}



$demo 1 = mydemo::getinstance ($a);

$demo 2 = mydemo::getinstance ($a);


This article is from the "Linux Warden" blog, so be sure to keep this source http://sswqzx.blog.51cto.com/2494644/1964702

PHP Single-instance mode

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.