0

I run into a lot of trouble migrating from my test server to production server because of case sensitive class name mismatches that aren't caught in test. The autoloader fails in production server (Linux) but does not catch errors on the test server (Windows). Is there a way to make my autoloader throw an error if the class name case does not match the file name case?

Here is the code:

function autoload_class_multiple_directory($class_name)
{
# List all the class directories in the array.
$array_paths = array('classes/HTMLelements/','classes/','secret/classes/');

# Count the total item in the array.
$total_paths = count($array_paths);

# Set the class file name.
$file_name = $class_name.'.php';

# Loop the array.
for ($i = 0; $i < $total_paths; $i++)
{
    if(file_exists($array_paths[$i].$file_name))
    {
        include_once $array_paths[$i].$file_name;
    }
}
}
Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
LaserCat
  • 150
  • 1
  • 17
  • 3
    Develop on a similar infrastructure, or get a pre-production staging/testing Linux server to check before you push stuff live. If you don't want to run Linux locally, you could always run your local code in a Linux VM. – ceejayoz Aug 24 '14 at 22:02
  • 3
    Just to make this clear: UNIX is case sensitive on filepaths. Windows isn't. And why are you using the same name (just with other capitals) for different classes? Use different names for different classes, make it visually distinguishable! – Charlotte Dunois Aug 24 '14 at 22:36
  • The problem is that the file name is Foo.php and the class name is Foo.php. But, if a call is made to foo (a typo on the case), it works in Windows, then fails in Unix. – LaserCat Aug 25 '14 at 11:00
  • Found a good solution here: http://stackoverflow.com/questions/3964793/php-case-insensitive-version-of-file-exists – LaserCat Aug 25 '14 at 11:27
  • 1
    @LaserCat you mean, that is what you want to prevent, right? to make it strict to prevent platfom incompatibility? – Sajuuk Aug 30 '17 at 13:17
  • based on the results of googling "force case sensitivity in windows" some may say that PHP is working fine - the problem is in the OS. Consider this one more vote for using a dev server or VM before pushing it out. If you use OS X, depending on what file system you are using and how it was created you can have case sensitivity - or not. – ivanivan Jan 17 '18 at 03:14

0 Answers0