ganjan
ganjan

Reputation: 7596

Include smarty in php's __autoload gives Class 'Smarty_Internal_Template' not found

I have a autoload function like this:

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;
    }

}

I renamed the smarty file to class.smarty.inc.php so it's included in the autoload, but I get this error:

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

Don't know what that mean..

Upvotes: 0

Views: 1868

Answers (2)

Crozin
Crozin

Reputation: 44386

Do NOT modify 3rd-party-libraries. Just create a second autoloader that follows Smarty's naming convention.

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');

Upvotes: 2

KingCrunch
KingCrunch

Reputation: 132031

The way your autoloader maps the classname to a filename leads to the filename class.smarty_internal_template.inc.php, which is obviously not the filename you expect. I dont know how Smarty is structured, but you should make sure the autoloader can find any of its classes.

Upvotes: 0

Related Questions