A Programmer’s Perspective twitter
A Programmer’s Perspective Rss

PHP Autoload Issue

Posted by Jason | Posted in php | Posted on 11-09-2008

0

On a recent project, I couldn’t figure out why the following block of code worked on OSX but not Red Hat Linux.


function __autoload($class_name) {
require_once 'lib/' . $class_name . '.class.php';
}

I had a class named ‘bank.class.php’ which autoload was attempting to find.  It worked properly on OSX, however on Linux it wouldn’t work.  I quickly discovered that Linux required the file to be renamed to ‘Bank.class.php’.  Alternatively I could have changed the autoload to:


function __autoload($class_name) {
require_once 'lib/' . strtolower($class_name) . '.class.php';
}

Write a comment