Search code examples
phpsplautoloader

PHP Autoloader and Unix Case-Sensitive File-System


I have index.php

<?php
    include('_controller/Autoloader.php');
    Gold_Autoloader::init();

    $mysql = new Gold_MySQL();

_controller/Autoloader.php

<?php
class Gold_Autoloader
{

    public static $loader;

    public static function init()
    {
        if (self::$loader == NULL)
            self::$loader = new self();

        return self::$loader;
    }

    public function __construct()
    {
        spl_autoload_register(array($this, 'controller'));
        spl_autoload_register(array($this, 'resources'));
    }

    public function resources($className)
    {
        $className = preg_replace('#Gold_#', '', $className);
        $className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);

        set_include_path(PROJECT_ROOT . '_resources');
        spl_autoload_extensions('.php');
        spl_autoload($className);
    }

    public function controller($className)
    {
        $className = preg_replace('#Gold_#', '', $className);
        $className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);

        set_include_path(PROJECT_ROOT . '_controller');
        spl_autoload_extensions('.php');
        spl_autoload($className);
    }
}

And I have file _controller/MySQL.php with Gold_MySQL.class. On windows system this code is working and including MySQL.php, but on hosting this code not working ((

[Thu Jan 27 12:55:57 2011] [error] PHP Fatal error: Class 'Gold_MySQL' not found in /home/u91167/youd0main.com/www/index_.php on line 5

EDIT

How to make so that Unix could look at any files? Zend has no files with a lowercase letter.


Solution

  • Sounds like your filename is case sensitive and you're trying to load a file in the wrong case. i.e. you might need gold_mysql.php instead of Gold_MySql.php?