在php中包含smarty';自动加载给类';Smarty#u内部#u模板';找不到

在php中包含smarty';自动加载给类';Smarty#u内部#u模板';找不到,php,smarty,template-engine,Php,Smarty,Template Engine,我有这样一个自动加载功能: function __autoload($class) { //define('DOCROOT', dirname(__FILE__)); $filename = "../sys/class/class." . strtolower($class) . ".inc.php"; //$filename = DOCROOT . "/sys/class/class." . strtolower($class) . ".inc.php";

我有这样一个自动加载功能:

function __autoload($class)
{
    //define('DOCROOT', dirname(__FILE__));

    $filename = "../sys/class/class." . strtolower($class) . ".inc.php";
    //$filename = DOCROOT . "/sys/class/class." . strtolower($class) . ".inc.php";

    if ( file_exists($filename) )
    {
            include_once $filename;
    }

}
我将smarty文件重命名为
class.smarty.inc.php
,因此它包含在自动加载中,但出现以下错误:

Fatal error: Class 'Smarty_Internal_Template' not found in /var/www/v3/sys/class/class.smarty.inc.php on line 441 

我不知道那是什么意思

自动加载程序将类名映射到文件名的方式会导致文件名
class.smarty\u internal\u template.inc.php
,这显然不是您期望的文件名。我不知道Smarty是如何构造的,但您应该确保自动加载程序可以找到它的任何类。

不要修改第三方库。只需按照Smarty的命名约定创建第二个自动加载器

function defaultAutoloader($className) {
    // your code ($file = /path/to/my/lib/{{ CLASS }}.inc.php)

    if (file_exists($file)) {
        require $file;
        return true;
    }

    return false;
}

function smartyAutoloader($className) {
    // code ($file = /path/to/smarty/{{ CLASS }}.php)

    if (file_exists($file)) {
        require $file;
        return true;
    }

    return false;
}

spl_autoload_register('defaultAutoloader');
spl_autoload_register('smartyAutoloader');

您应该始终使用
spl\u autoload\u register()
,因为如果其他库在那里注册自动加载器,
\u autoload()
将不再被调用(
spl\u autoload\u register(“\uu autoload”);
)不能说我同意您的第一句话,在我的书中修改第三方库没有错,但它现在起作用了。谢谢