【PHP设计模式】单例设计模式


class Single
{
    private static $_instance;
    private function __construct()
    {
        echo "初始化一次
"; } private function __clone() { // TODO: Implement __clone() method. } public static function getInstance(){ if(!self::$_instance instanceof self){ self::$_instance = new self(); } return self::$_instance; } public function test() { echo "test
"; } } Single::getInstance()->test();