I’m running the latest version of XAMPP and autoload() doesn’t seem to be working as it should. I pretty much replaced my previous autoload with the one from the PHP manual, but to no avail.
After putting a few echo’s and die()s, I’ve concluded that __autoload isn’t being invoked at all.
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;
}
}
It doesn’t output the “hello” that is located at the very top of __autoload().
The only output is:
Fatal error: Class ‘Config’ not found
in E:\xampplite\htdocs\system\Main.php
on line 84
__autoloaddoesn’t go in the class. It’s used to include the file the class is in.You’ll need to add an autoload function to the initial script to ever have it do anything.