Namespace Autoload works under windows, but not on Linux

autoload, namespaces, php

Solution

The SPL autoloader is extremely primitive - it has no knowledge of namespaces, so it tries to load a file with \ in it's name while on Linux/Unix the path separator is / not .

Problem

I have the following php code: index.php ``` <?php spl_autoload_extensions(".php"); spl_autoload_register(); use modules\standard as std; $handler = new std\handler(); $handler->delegate(); ?> ``` modules\standard\handler.php ``` <?php namespace modules\standard { class handler { function delegate(){ echo 'Hello from delegation!'; } } } ?> ``` Under Windows 7, running WAMP, the code produces the message "Hello from Delegation!" however under Linux, I get the following: Fatal error: spl_autoload(): Class modules\standard\handler could not be loaded in /var/www/index.php on line 15 Windows is running PHP 5.3.0 under WAMP, and Linux is running the 5.3.2 dotdeb package under Ubuntu 9.10. Is this a configuration issue on my linux box, or just a difference in the way namespaces and autoloading is handled on the different operating systems

Original source