LeKoala - web and design - with a pinch of eucalyptus

web and design - with a pinch of eucalyptus

The best autoloader

If you are a PHP developper, you probably already know about PSR-0 autoloaders. And really, it was great to see efforts to have a consistent naming convention, allowing great things like Composer.

But I've always wondered: why on earth would you have a specific implementation when PHP provide one by default.

And indeed, I find myself using more and more this:

set_include_path(__DIR__ . PATH_SEPARATOR . get_include_path());
spl_autoload_extensions(".php");
spl_autoload_register();

I mean... three lines, namespace support, native performance... I really don't see the reason why not to use this. Well, there is one: it looks for lowercased filenames. And if you want your naming system to also work in PSR-0, you have to use lowercase class names... which is ok, I think, it saves the shift key on your keyboard so why not?

PS: by the way, if you are looking for a rational reason to use "echo" vs "print", here's one : it's one less letter to type :-)