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.
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.