代码之家  ›  专栏  ›  技术社区  ›  therufa

挖掘两个或多个对象

  •  0
  • therufa  · 技术社区  · 14 年前

    这样地:

    class core
    {
    
        public function __get($class)
        {
            $this->load($class);
        }
    
        public function load($class, $file = null, $lib = true)
        {
            if($file == null)
                $file = $class;
    
            if($lib == true)
                include(LIBPATH.$file.PHP);
            else
                include(SYSPATH.$file.PHP);
    
            $this->$class = new $class($this);
        }
    
    }
    

    class Child implements myStruct
    {
        public function __construct($obj)
        {
             $this->obj =& $obj;
        }
    }
    

    这是像我想的那么难看,还是这个解决方案可以接受?

    1 回复  |  直到 14 年前
        1
  •  3
  •   Artefacto    14 年前

    这绝对是次优的。第一:

    $this->obj =& $obj;
    

    $this->obj = $obj .

    spl_autoload 用于自动加载类。它并不等同于您正在做的事情--您使用某种容器来保存对对象的引用(每个类只有一个对象),但我怀疑这正是您想要的。