Whenever I try to use namespaces for my classes I get an error saying the class is not found or some sort, I've tried both on a free domain and a .com domain with a paid hosting. Why is that happening?...
Take for instance, I have a controllers folder and a pagesController.php function with the namespace of App\Controllers, in my autoload register I load the controllers if one is instantiated and it works fine on my local development. When I move those files to the web hosting, it'll just throw an error.
I found the issue with using namespaces... I had to use ____dir____ and then use the two dots to send it one folder back, for some reason using the 'ROOT' constant wouldn't work even though the path file was the same.
```
<?php
use app\classes\App as App;
require ROOT . '/vendor/autoload.php';
require 'functions.php';
spl_autoload_register(function ($class_name) {
$validNameSpaces = [
'app\controllers\\', 'app\models\\', 'app\classes\\'
];
foreach($validNameSpaces as $namespace) {
if(strpos($class_name, $namespace) === 0) {
$path = __DIR__ . '/../' . strtr($class_name, '\\', '/') . '.php';
if(is_file($path) && is_readable($path)) {
include_once $path;
return true;
}
}
}
return false;
});
App::instance();
include_once "routes.php";
```