Create an autoloader in PHP

***** FILE STRUCTURE *****src/App/Main.phpNewNamespace/Main.phpcomposer.jsonindex.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 :
<?phprequire __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.
run composer dump-autoload again so these changes can be installed.