PHP 的单例模式代码

2015-01-06 0 393
PHP 的单例模式代码
class User {
    static function getInstance()
    {
    if (self::$instance == NULL) { // If instance is not created yet, will create it.
        self::$instance = new User();
    }
    return self::$instance;
    }
    private function __construct() 
    // Constructor method as private  so by mistake developer not crate
    // second object  of the User class with the use of new operator
    {
    }
    private function __clone()
    // Clone method as private so by mistake developer not crate 
    //second object  of the User class with the use of clone.
    {
    }

    function Log($str)
    { 
    echo $str;
    }
    static private $instance = NULL;
}
User::getInstance()->Log("Welcome User");

遇见资源网 php PHP 的单例模式代码 http://www.ox520.com/7164.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务