Discuz X single-piece Mode

Source: Internet
Author: User

This article introduces an original article about discuz X single-piece mode. The PPC highlight plug-in is too unfriendly. It may be strange to paste txt content directly.

As long as there is such a sentence at the beginning of the file

The Code is as follows: Copy code

$ Discuz = & discuz_core: instance ();
[Code language = php]

 

// Instance () belongs to the discuz_core class in class_core.php
Function & instance (){
Static $ object;
If (empty ($ object )){
$ Object = new discuz_core ();
}
Return $ object;
}
[/Code]
Make sure that a discuz_core instance is used for all word requests. Here, & is written to be compatible with PHP4. If it is in PHP5, you can use static.
[Code language = php]
// Here is a simple example of the single-piece mode.
Class PHPig {
Private static $ v = null;
Static function instance (){
If (self: $ v = null ){
Self: $ v = new PHPig ();
}
Return self: $ v;
}
}
$ Pig1 = PHPig: instance ();
$ Pig2 = PHPig: instance ();
If ($ pig1 ===$ pig2 ){
Echo 'same object ';
} Else {
Echo 'not the same object ';
}
[/Code]


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.