I have this folder structure in my PHP project. (this is as shown in eclips)
-MySystem
+Code
+Data_Access
-Public_HTML
+css
+js
At this moment, PHP itself does not provide a way to get the project's root directory for sure.
But you can implement a very simple method yourself that will do exactly what you're looking for.
Solution
Create a new file in your project, let say D:/workspace/MySystem/Code/FilesManager.php (use whatever name and path suit you the best). Then, use the following code:
Now you can do this in, let's say D:/workspace/MySystem/Code/a/b/c/Feature.php:
echo FilesManager::rootDirectory();
And the expected result should be:
"D:/workspace/MySystem"
The output will be the same no matter where your "feature" file is located in the project.
Explanation
dirname is used to return the parent directory of the first parameter. We use the magic constant __FILE__ to give it FilesManager.php's path. The second parameter tells how many times to go up in the hierarchy. In this case, we need to do it twice, but it really depends where you put your file in the hierarchy. You can omit the second parameter if you only need to got up once, meaning the file is located in the root. But then, you can return __DIR__ directly instead.
This solution is guaranteed to work, no matter where the root is located on your server. Unless you end up moving the utility class somewhere else in the hierarchy.
Additional note
I'd avoid using DOCUMENT_ROOT for the following reasons (according to this answer):