Autoloading Class Problem With Smarty

PHP with Smarty Template Engine

PHP with Smarty Template Engine

If you are using Smarty Template engine with your PHP code and you happen to use an autoloader, then you may have encountered an autoloading class problem with Smarty  stating that the file “Smarty_Internal_TemplateBase” can’t be found and your script produces a FATAL error. Smarty is using it’s own autoloader using the spl_autoload_register method and our autoloader is messing it up.

The code above will fire automatically for all missing class files and since we are looking for a file inside “classes” directory, it will end up as a missing file due to the fact that the “missing” file is under Smarty’s installed folder.

Easy Manual Fix

We can fix this by expanding our autoloader to include Smarty’s folder and hard coding everything inside.

It is working ok but what if we need to add another 3rd party framework that have it’s own autoloader?

Easy Permanent Fix

To correct the problem, we need to register our own spl_autoload_register using the code below..

We just told PHP to add a new autoloading class function for us named “autoload” which will run parallel with Smarty’s autoloder function.


The TechnoJunkie of the group who studied engineering but got stuck with software development. Remember kids, 90% of your problems can be solved by marketing. Solving the other 10% just requires good procrastination skills.

You may also like...

Leave a Reply

%d bloggers like this: