PHP包括路径设置

时间:2014-01-26 18:54:00

标签: php

我确定我只是有点愚蠢,但include_path文档似乎有点令人困惑;什么是

Using a . in the include path allows for relative includes as it means the 
current directory. However, it is more efficient to explicitly use include
'./file' than having PHP always check the current directory for every include. 

实际上是想说?

2 个答案:

答案 0 :(得分:2)

  

是什么

     
    

使用。在include路径中允许相对包含,因为它意味着     当前目录。但是,明确使用include更有效     '。/ file'比让PHP总是检查每个包含的当前目录。

  
     

实际上是想说?

当您未明确指定路径时,假设您要使用include_path在文件夹/somepath/foo/includes中搜索包含文件。你可能有大部分的包含文件,所以这应该不是太低效。

现在您要从该目录中加入baz.phpxzy.php123.php - 如果您已在.中首先提供include_path,那么PHP将会始终首先搜索当前目录,但在大多数情况下,该文件将位于/somepath/foo/includes文件夹中。

如果在包含路径的开头指定.,并在包含当前目录中的文件时明确使用./abc.php(特殊情况,不是您的“正常”包含的内容之一,那么对于您使用baz.phpxzy.php123.php包含的所有其他包含文件,PHP将会必须首先搜索当前目录 - 这是无用的,因为这些文件位于您的特殊包含文件夹中;所以PHP可以首先看一下。

答案 1 :(得分:0)

正在讨论include_path开头的dot。

表单PHP文档:If filename begins with ./ or ../, it is looked only in the current working directory.

./ is the current directory. It is largely the same as just someFile.php.In many cases \it doesn't check any standard places PHP might look for a file, instead checking only the current directory.

Edited.'效率更高'意味着最好用dot设置路径。换句话说,它不仅会尝试在当前工作目录中查找。因此,如果您想在某个目录中包含文件,但是该文件不存在,它会尝试在其他路径中查找,并且可能需要一些时间并且包含错​​误或只是错误,这可能是一个问题。< / p>

相关问题