单例Demo

<?php

class T
{
    public $client = [];
    protected static $instance;

    protected function __construct()
    {

    }

    public function getInstance($a = '')
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        if (!isset(self::$instance->client[$a])) {
            self::$instance->client[$a] = $a;
        }
        return self::$instance;
    }

    public static function index()
    {
        echo '<pre>';
        var_dump(self::$instance->client);
    }
}
T::getInstance('a')->index();
T::getInstance('b')->index();
T::getInstance('c')->index();
T::getInstance('d')->index();
T::getInstance('e')->index();
Posted in