输入banner图图片脚本导航/分类

phpsingleton单例模式入门例子

  1. class CC
  2. {
  3. //单例模式
  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. ?>

2、index.php文件:

  1. 测试php单例模式
  2. require 'common.php';
  3. $objCC=CC::singleton();
  4. $r=$objCC->EventResult(7);
  5. print_r($objCC);
  6. echo $r."
    ";
  7. ?>