Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

This application shows us how to implement PSR-4 standard in order to use a common "namespace" for all our classes in our application.


composer.json


{
"autoload": {
"psr-4": {
"Application\\": "src/Application/"
}
}
}

Any class located under src/Application/ folder or sub folders, will use Application namespace like shown below.


# src/Application/ClassOne.php

<?php

namespace Application;

class ClassOne
{
...
}

# src/Application/Service/ClassTwo.php

<?php

namespace Application\Service;

class ClassTwo
{
...
}

Our application structure looks like below.


| root/
| - src/
| - Application/ # namespace itself
| - Service/
| ClassOne.php # namespace Application\Service
| ClassTwo.php # namespace Application
| composer.json