php singleton singleton mode entry example

WBOY
Release: 2016-07-25 08:51:27
Original
982 people have browsed it
  1. class CC
  2. {
  3. //Single case mode
  4. private static $ins;
  5. public static function singleton()
  6. {
  7. if (!isset(self::$ins)){
  8. $c = __CLASS__;
  9. self::$ins = new $c;
  10. }
  11. return self::$ins;
  12. }
  13. public function EventResult($Id)
  14. {
  15. return $Id;
  16. }
  17. }
  18. ?> ;
Copy code

2. index.php file:

  1. Test php singleton mode
  2. require 'common.php';
  3. $objCC=CC::singleton();
  4. $ r=$objCC->EventResult(7);
  5. print_r($objCC);
  6. echo $r."
    ";
  7. ?>
  8. < /p>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template