What does the dot-slash do to PHP include calls?

Robin Rodricks picture Robin Rodricks · Feb 23, 2009 · Viewed 14.5k times · Source

A. What does this do?

require ("./file.php");

B. in comparison to this?

require ("file.php");

(Its not up-one-directory.. which would be)

require ("../file.php");

Answer

Chris Lutz picture Chris Lutz · Feb 23, 2009

./ is the current directory. It is largely the same as just file.php, but in many cases (this one included) it doesn't check any standard places PHP might look for a file, instead checking only the current directory.

From the PHP documentation (notice the last sentence):

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.