将对象注册到一个类中
通过该类实现全局访问操作对象

<?php

namespace Lib;

class Register
{
    public static $objects;
    public static function set($alias , $obj)
    {
        self::$objects[$alias] = $obj;
    }

    public static function get($alias)
    {
        return isset(self::$objects[$alias] ) ? self::$objects[$alias] : null;
    }

    public static function _unset($alias)
    {
        unset(self::$objects[$alias]);
    }
}
    $user = new \Lib\User($id);
    Register::set($key,$user);

results matching ""

    No results matching ""

    results matching ""

      No results matching ""