所以我用'spl_autoload_register'我index来加载一堆.classes因为我lazy,正如你在下面我的自动加载构造中看到的那样,我也functions从一些调用auto-loaded classes来运行我的应用程序。
在我的项目范围内,我无法$this->function在另一个function中引用例如auto-loaded class,也许我不理解事物是如何像这样实例化的。
我想要一个允许程序和 OOP 结构的项目的最有效方法,但我真的很喜欢使用$this大声笑,我如何能够$this在我的自动加载器加载的类中有效地使用和使用它,我会编辑吗? init() 也许允许$this?
请原谅我制作项目的无知,并且不了解编码结构的最新情况。
self::也应该乖乖的static::?
类->自动加载->索引
class autoloader {
public static $loader;
public static function init()
{
if(self::$loader == NULL) {
self::$loader = new self();
}
return self::$loader;
}
public function __construct() {
spl_autoload_register(array(this, 'library'));
request::request();
template::render();
}
public function library($class)
{
set_include_path(get_include_path() . PATH_SEPARATOR . '/lib');
spl_autoload_extensions('.class.php');
spl_autoload($class);
}
}