I am using PSR-0 for auto loading, I know that I need to use PSR-4 which I will do it latter part. Even if PSR-4, answers are welcome.
I am having the following directory structure for which the auto loading works fine.
+ www/entity
|__ /EntityGenerator
| |__ /Database
| | |__ DatabaseConnection
| | |__ DatabaseConnectionInterface
| | |__ DatabaseRepositoryInterface
| |
| |__ /Exception
|
|__ autoload.php
|__ index.php
For the following directory structure its giving error as follows
Warning: require(EntityGenerator\Database\DatabaseConnection.php): failed to open stream: No such file or directory in C:\wamp\www\entity\EntityGenerator\autoload.php on line 15
+ www/entity
| __ /EntityGenerator
|__ /Database
| |__ DatabaseConnection
| |__ DatabaseConnectionInterface
| |__ DatabaseRepositoryInterface
|
|__ /Exception
|__ autoload.php
|__ index.php
Can anyone explain why I am getting the error with second directory structure.
If anyone needs the whole code for testing, please find the below link
Your problem is you're using a relative path, which is not always set as the current script's directory. You need to use absolute paths to be sure you're loading what you need to load.
__DIR__
is guaranteed to return the directory which the current script is in.