spl_autoload - Case insensitive

Hi:

I developed my app using Zend and Autoloader function. when I deployed it, it din’t seem to work. after a while I came across http://bugs.php.net/bug.php?id=49625.

is there a way to work around that rather than changing names for all folders and files on case sensitive systems?

I am sure there is a work around for this already. i searched the forum but couldn’t find anything.

Please help.

Register your own autoloader with spl_autoload_register() (or Zend Framework’s equivalent) and it can look for the files in any way that you like, including in the proper case.

As Salathe states, just create another autoloader implementation.

The SPL Autoloader is stacked, which means you can register more than one loader for your application and it will try each one in order.


<?php
function lower_load($class){
  normal_load(strtolower($class));
}

function normal_load($class){
  #do stuff here
}

spl_autoload_register('lower_load');
spl_autoload_register('normal_load');

Something similar to this should resolve it.

Hi:

I do have my own loader but those are the ones not working. It maybe that I am implementing those wrong. The second one works on that system but I was hoping to avoid “include”.


/* put the custom functions in the autoload register when the class is initialized */
        private function __construct($configArr){
            $this->_src = $configArr['autoloaderPath'];
            $this->_ext = $configArr['autoloaderExt'];
            $this->docroot = $configArr['documentRoot'];
            //We will only use clean method rather than include
           // spl_autoload_register(array($this, 'clean'));
            spl_autoload_register(array($this, 'dirty'));
        }
/* the clean method to autoload the class without any includes, works in most cases */
        private function clean($class){
            $class=str_replace('_', '/', $class);
            spl_autoload_extensions(implode(',', $this->_ext));
            foreach($this->_src as $resource){
                set_include_path($this->docroot . $resource);
                spl_autoload($class);
            }
        }
       
        /* the dirty method to autoload the class after including the php file containing the class */
        private function dirty($class){
            $class=str_replace('_', '/', $class);
            foreach($this->_src as $resource){
                foreach($this->_ext as $ext){
                set_include_path($this->docroot . $resource);
                    if(file_exists($this->docroot . $resource . $class . $ext)){
                        include($this->docroot . $resource . $class . $ext);
                        
                        spl_autoload($class);
                        break;
                    }
                }
            }
            
        }