troelskn / konstrukt

A HTTP-friendly framework of controllers for PHP5.
http://konstrukt.dk/
Other
99 stars 14 forks source link

autoloader fails on case-sensitive file systems #3

Open ghost opened 14 years ago

ghost commented 14 years ago

I propose creating $filename like so in k_autoload:

$filename = preg_replace(
  '/([A-Za-z0-9]+)_/e',
  "strtolower('$1').'/'", 
  $classname
) . '.php';

The existing autoloader makes everything lower-case, and this instead leaves the last part of the underscore-separated class path alone: "Path_To_SomeClass" becomes "path/to/SomeClass.php".

lsolesen commented 13 years ago

How about this? I agree that the standard autoloader should not make assumptions on how the developer wants to name classes.

troelskn commented 13 years ago

The autoloader will make assumptions in any case. If you don't lowercase, then you assume that files are named in the same fashion as the are referred in code.

Granted, the de-facto standard (PEAR and ZF inclusive) use a mixed case for file names. I have used all lower case for a long time, because class names are case insensitive in PHP, thus there is no guarantee that a user has typed a class name in the same case in every place. It's not that I want to impose any particular style really - Konstrukt it self doesn't rely on autoload functionality, so perhaps the right thing to do would be to simply remove the autoloader from the library and leave it to user land to implement this functionality.

lsolesen commented 13 years ago

It is difficult, I think. If you include the autoloader, I think it should work according to the standard (PEAR and ZF). Otherwise it will confuse too many users.

troelskn commented 13 years ago

I think I concur.