<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_48260"> <div class="blockcode"> <div id="code_pEE"><ol> <li> <li><?<li>class mysql{<li> privete static $instance ;//保存实例<li> //构造函数声明为private, 防止直接创建对象<li> privete function __construct(){<li> // 实例化<li> }<li> //单例方法, 判断是否已经实例化,只实例化一次<li> public static function getInstance (){<li> if(!isset( self::$instance )){<li> self ::$instance = new self();<li> }<li> return self:: $instance;<li> }<li> //防止克隆对象<li> private function __clone (){<li> trigger_error ("not allow to clone.");<li> }<li> function test(){<li> echo "test" ;<li> }<li>}<li>$conn = mysql::getInstance ();<li>$conn->test ();</li> <li>?></li> </ol></div> <em onclick="copycode($('code_pEE'));">复制代码</em> </div> </td></tr></table> <div id="comment_48260" class="cm"> </div> <div id="post_rate_div_48260"></div> <br><br>