This is my code that autoloads and calls/instantiates my classes
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();
}
When I call $this->helper I get this error
Fatal error: Call to a member function test() on a non-object in (...)
So my question is, are the classes still being loaded when the __get() method is called?
And yes, the method test() does exist in my Helper class
It should be
$this->_helper->test();as your code is doing:$this->{'_' . $name} = new $classname();Your magic method is re-instantiating the class each time it’s called. You should have it check if it’s
nullfirst: