***** FILE STRUCTURE *****
src/
App/
Main.php
NewNamespace/
Main.php
composer.json
index.php
{
}
run composer install
This will generate a series of autoload files.
{
"autoload": {
"psr-4": {
"App\\": "src/App",
"App\\NewNamespace\\": "src/App/NewNamespace"
}
}
}
This represents the autoloader type "psr-4" plus the key is the namespace and the value is the src/App folder. Here it will autoload all the namespace App files.
run composer dump-autoload
This will generate the autoloader files needed for this to work. Then in index.php :
<?php
require __DIR__ . '/vendor/autoload.php';
new App\Main;
new App\NewNamespace\Main;
Here we import the autoloader file so we can import all the namespace App classes. Here we then new up the class Main within the namespace App.