The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

$_SERVER['DOCUMENT_ROOT'] OR realpath()?

Usually I use this to define the path to directory which contains the scripts:
realpath(dirname(__FILE__))

so at the very beginning of the index.php I can put something like this:
define('SITE_PATH', realpath(dirname(__FILE__)));

Then I can use SITE_PATH inside any class anytime I need to get value of root dir, so If I need to get absolute path to 'images' directory, I would use
SITE_PATH_PATH . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;

This works, but I saw another post where someone asked about the use of
$_SERVER['DOCUMENT_ROOT']
the $_SERVER['DOCUMENT_ROOT'] is doing pretty much the same thing as realpath(dirname(__FILE__)) right?

Now I am wondering, when should I use realpath(dirname(__FILE__)) and when to use $_SERVER['DOCUMENT_ROOT']?

Which one is the preferred way to get the path of my scripts root directory?

Zend is doing: realpath( dirname(__FILE__) . '/../library' ), Notice '/../library' is being appeneded to dirname's output before realpath? If you are just using dirname and __FILE__ realpath is surpflouse. Zend is using realpath to transform the relative path ('/../library') appended into absolute.

Edit: Well scrolling down a bit more I see it now...cannot tell you why Zend is suggesting that bit its not needed.

Logic without the fatal effects.
All code snippets are licensed under WTFPL.

Zend is doing: realpath( dirname(__FILE__) . '/../library' ), Notice '/../library' is being appeneded to dirname's output before realpath? If you are just using dirname and __FILE__ realpath is surpflouse. Zend is using realpath to transform the relative path ('/../library') appended into absolute.

Edit: Well scrolling down a bit more I see it now...cannot tell you why Zend is suggesting that bit its not needed.

Yes, in one place, but on the same page they have example with just
define('APPLICATION_PATH', realpath(dirname(__FILE__)));
I think realpath() is still necessary in case there are any symlinks in the path returned by __FILE__