欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)singleton()單例模式實例

 更新時間:2014年11月06日 09:57:31   投稿:shichen2014  
這篇文章主要介紹了php實現(xiàn)singleton()單例模式的方法,以實例形式簡單講述了單例模式的實現(xiàn)過程,需要的朋友可以參考下

本文實例講述了php實現(xiàn)singleton()單例模式的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

common.php文件如下:

復(fù)制代碼 代碼如下:
<?php 
class 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文件如下:
復(fù)制代碼 代碼如下:
<html> 
    <head> 
        <title>測試</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    </head> 
    <body> 
<?php 
require 'common.php'; 
$objCC=CC::singleton(); 
$r=$objCC->EventResult(7); 
print_r($objCC); 
echo $r."</br>"; 
?> 
</body></html>

希望本文所述對大家的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論