标签:对象 name get his 一个 eof var class vat
class Single{ //定义一个属性 public $siteName; //本类的静态实例 protected static $instance = null; //私有的构造方法 private function __construct($siteName=‘‘){ $this->siteName = $siteName; } //获取本类的唯一实例 public static function getInstance($siteName=‘PHP‘){ if(!self::$instance instanceof self){ self::$instance = new self($siteName); } return self::$instance; } } //工厂模式 class Factory{ //创建指定类的实例 public static function create(){ return Single::getInstance(‘HTML JS CSS‘); } } //注册树模式 class Register{ public static $obj = []; public static function set($alias,$objects){ self::$obj[$alias] = $objects; } public static function get($alias){ return self::$obj[$alias]; } public static function _unset($aliass){ unset(self::$obj[$alias]); } } //注册一个hello类的实例,放到对象池 Register::set(‘hello‘,Factory::create()); //从对象池中获取hello类 $obj = Register::get(‘hello‘); //查看属性 var_dump($obj->siteName);
标签:对象 name get his 一个 eof var class vat
原文地址:https://www.cnblogs.com/gyfluck/p/9994115.html