What's better of require(dirname(__FILE__).'/'.'myParent.php') than just require('myParent.php')?

后端 未结 4 1288
情书的邮戳
情书的邮戳 2020-12-08 03:27

Lots of famous PHP scripts including WordPress use dirname(__FILE__).\'/myParent.php\' instead of just \'myParent.php\' when including files in the

4条回答
  •  甜味超标
    2020-12-08 03:47

    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.

提交回复
热议问题