最近我开始使用 OOP 并创建了一个类加载器来加载我使用的类。所以我制作了这个类并使用它(本地)并且一切都很好。但是当我将所有内容上传到我的虚拟主机时,它就停止了工作。当我访问加载程序需要加载类的页面时出现以下错误..
Fatal error: Uncaught exception 'Exception' with message 'Class "formhandler" could not be autoloaded from:
/var/www/vhosts/***.nl/httpdocs/admin/lib/formhandler.php' in
/var/www/vhosts/***.nl/httpdocs/admin/index.php:30 Stack trace:
#0 /var/www/vhosts/***.nl/httpdocs/admin/index.php(109): __autoload('formhandler')
#1 {main} thrown in /var/www/vhosts/***.nl/httpdocs/admin/index.php on line 30
我的自动加载器的代码如下..
function __autoload($className)
{
// get the base dir.
$base = dirname(__FILE__);
// get path
$path = $className;
$file = $base . "/lib/" . $path . '.php';
//if exists get file else throw error
if (file_exists($file))
{
require $file;
}
else
{
error_log('Class "' . $className . '" could not be autoloaded');
throw new Exception('Class "' . $className . '" could not be autoloaded from: ' . $file);
}
}