Php 通过_get()实例化时找不到自动加载的类

Php 通过_get()实例化时找不到自动加载的类,php,Php,这是我的代码,自动加载和调用/实例化我的类 public function __get($name) { $classname = '\\System\\' . ucfirst($name); if (property_exists($this, '_' . $name)) $this->{'_' . $name} = new $classname(); else echo $name . ' isn\'t a valid prop

这是我的代码,自动加载和调用/实例化我的类

public function __get($name)
{
    $classname = '\\System\\' . ucfirst($name);

    if (property_exists($this, '_' . $name))
        $this->{'_' . $name} = new $classname();
    else
        echo $name . ' isn\'t a valid property.';
}


private function boot()
{echo "<pre/>";
    spl_autoload_register(null, false);

        if (function_exists('__autoload'))
            spl_autoload_register('__autoload');

        spl_autoload_register(array($this, 'libraries'));
var_dump($this->helper);
        //$this->configuration();
}
所以我的问题是,调用
\uu get()
方法时是否仍在加载类


是的,方法
test()正如您的代码所做的:
$this->{''.'$name}=new$classname()

您的神奇方法是在每次调用类时重新实例化它。您应该先让它检查它是否为
null

if (property_exists($this, '_' . $name) && $this->{'_' . $name} !== null)

当它是一个完全成熟的项目时,这一定是一个很难维护的问题。
is\u null()
也会这样吗?因为我想实例化属性是否为null,对吗?是的,
is\u null
具有相同的效果。
if (property_exists($this, '_' . $name) && $this->{'_' . $name} !== null)