Lots of famous PHP scripts including WordPress use dirname(_FILE_).'/myParent.php' instead of just 'myParent.php' when including files in the same directory of the currently running script.

Aren't they the same thing? Why do you prefer typing more?

Thanks.

Accepted Answer

PHP needs to know the absolute path to the file. dirname(__FILE__).'/myParent.php' already is the absolute path but 'myParent.php' requires a lookup using the given paths in include_path to get an absolute path and find the file. A better choice would be './myParent.php':

However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include.

Written by Gumbo
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki