I have a problem here. I have created the namespace for all classes. previously i was using windows 7 to develop current app, everything is fine. now i just moved to ubuntu, the problem comes.
index.php
spl_autoload_extensions(".php");
/*spl_autoload_register(function ($class) {
require __DIR__ . '/../' . $class . '.php';
});*/
//provided i have tried the above method, which works on windows 7 but not Ubuntu
spl_autoload_register(function ($class) {
require '/../' . $class . '.php';
});
//for your info, i do this
//require "../resources/library/Config.php";
//it works, no error
use resources\library as LIB;
use resources\dal as DAL;
//instantiation
$config = new LIB\Config();
print_r($config->fbKey());
i got this error
PHP Warning: require(../resources\\library\\Config.php): failed to open stream: No such file or directory in /home/user/dir1/dir2/index.php
i cannot find the error. hope you guys can help me with this. any question don hesitate to comment i will edit. thanks in advance.
UPDATE – Extra Info
PHP version 5.4.6
LATEST UPDATE
any idea how to solve this without using str_replace ? JULP and MOONWAVE have the answer!
Which PHP version do you use? (in PHP < 5.3.3, default spl_autoload_register was not namespace aware – I mean \ was not replaced by / on Unix systems)
In your code, try to replace:
By:
=> Always use slashes in path, they work everywhere. Backslashes, don’t. And don’t forget filenames are case sensitive on Unix systems, the opposite of Windows.