<?php

/**
 *
 *单例模式
 *
 *
 *
 *
 */

class car2
{
    //私有静态变量
    private static $_instance;
    //构造函数私有
    private function __construct()
    {
        echo 'wo bei shi li hua!';
    }
    //获取实例
    public static function get_instance()
    {
        if(isset(self::$_instance))
        {
            return self::$_instance;
        }
        else
        {
            return self::$_instance = new self();
        }
    }
    //克隆函数 私有
    private function __clone()
    {
        trigger_error('jin zhi fu zhi',E_USER_ERROR);
    }

    function test()
    {
        echo "test";
    }
}
//使用类的静态方法获取实例
$test = car2::get_instance();
$test->test();
echo "<br>";
//在此获取实例
$test = car2::get_instance();
$test->test();
//复制一份实例,由于克隆函数私有,报错
//$test_other = clone $test;