最近我开始使用OOP,并创建了一个classLoader来加载我使用的类。。所以我上了这门课,并与它(本地)合作,一切都很顺利。但当我把所有东西上传到我的网络主机时,它就停止了工作。当我访问加载程序需要加载类的页面时,我得到了以下错误。。
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);
}
}
比较formhandler
类的生产路径。我保证它和/var/www/vhosts/.nl/httpdocs/admin/lib/formhandler.php
之间会有区别。更正。
我找到了解决方案。我有了新的formhandler();但我不得不使用新的FormHandler();在我的脚本中,因为我的网络主机没有;I don’我觉得它很烦人,但它现在起作用了!