Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace Autoload works under windows, but not on Linux

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

like image 570
EvilChookie Avatar asked May 19 '10 00:05

EvilChookie


1 Answers

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 .

like image 124
johannes Avatar answered Sep 26 '22 18:09

johannes