X, as long as there's a word at the beginning of the file.
The code is as follows |
Copy Code |
$discuz = & Discuz_core::instance (); [code language=php] The //instance () belongs to the Discuz_core class in the class_core.php function &instance () { static $object; If Empty ($object ) { $object = new Discuz_core (); } return $object; } [/code] guarantees that word requests use a Discuz_core instance. The & is written here to be compatible with PHP4, and if you are in PHP5, you can use static. [code language=php] ///This is a simple example of a single piece pattern. Class Phpig { private static $v = null; static function instance () { if (self:: $v = null) { &N bsp; self:: $v = new Phpig (); } return self:: $v; } $pig 1 = phpig::instance (); $pig 2 = phpig::instance (); if ($pig 1 = = $pig 2) { echo ' same object '; else { echo ' is not the same object '; } [/code] |