php singleton()

来源:互联网 发布:到哪里投诉淘宝网 编辑:程序博客网 时间:2024/05/20 21:48
common.php 

 

<?phpclass CC{private static $ins;public static function singleton() {         if (!isset(self::$ins)){            $c = __CLASS__;            self::$ins = new $c;         }         return self::$ins;    }public function EventResult($Id){return $Id;}}?>


 

 

index.php

<html>    <head>        <title>测试</title>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    </head>    <body><?phprequire 'common.php';$objCC=CC::singleton();$r=$objCC->EventResult(7);print_r($objCC);echo $r."</br>";?></body></html>


 

原创粉丝点击