This is a common issue, and its solution depends on your application architecture.
Document Root is not the path to your project directory, its the path to the server base directory - i.e. the directory that http://localhost/ maps to.
My typical application works by routing every request to index.php. Therefore I simply use DIR in index.php to get the root.
Would it not make more sense to use a relative path?