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] |