【发布时间】:2011-02-03 21:27:20
【问题描述】:
我正在运行最新版本的 XAMPP,但 autoload() 似乎无法正常工作。我几乎用 PHP 手册中的自动加载替换了我之前的自动加载,但无济于事。
在输入了几个 echo 和 die() 之后,我得出结论,__autoload 根本没有被调用。
class Main
{
var $config_data;
function __autoload($class_name) {
echo "hello.";
// If the file exists, require it
if (file_exists(SYSTEMDIR.$class_name.".".EXT)) {
echo 'Autoloader: The class exists.';
(require_once(SYSTEMDIR.$class_name.".".EXT))
or die("I tried to autoload class $class_name, but it failed! =(");
} else {
// The file didn't even exist. Die.
die("I was going to autoload class $class_name, but it didn't exist! =(");
}
}
/*
* Function __construct
* @param datatype variable description
* @return datatype description
*/
function __construct(/* $arg */) {
//Load the config
$this->config = new Config;
//Load the uri class:
$this->uri = new Uri;
}
}
它不输出位于 __autoload() 最顶部的“hello”。
唯一的输出是:
致命错误:找不到类“配置” 在 E:\xampplite\htdocs\system\Main.php 在第 84 行
【问题讨论】:
-
你能把__autoload放到一个类里面吗?您想将自动加载用作一般功能,不是吗?。