简体   繁体   English

PHP的include_path设置

[英]PHP's include_path setting

I'm sure I'm just being a bit stupid, but the include_path docs seem to be a bit confusing; 我确定我只是有点愚蠢,但include_path文档似乎有点令人困惑; what is 什么是

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. 

actually trying to say? 实际上想说?

what is 什么是

Using a . 用一个 。 in the include path allows for relative includes as it means the current directory. 在include路径中允许相对包含,因为它表示当前目录。 However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include. 但是,显式使用include'。/ file'比让PHP始终检查每个include的当前目录更有效。

actually trying to say? 实际上想说?

Assume you want to use include_path to search in folder /somepath/foo/includes for include files when you do not specify the path explicitly. 假设您未在显式指定路径时使用include_path在文件夹/somepath/foo/includes搜索包含文件。 You may have most of your include files laying there, so that should be not too inefficient. 你可能有大部分的包含文件,所以这应该不是太低效。

Now you are including baz.php , xzy.php and 123.php from that directory – and if you have given . 现在你要从该目录中包含baz.phpxzy.php123.php - 如果你已经给出了. first in the include_path , then PHP will search the current directory first always, although in most cases the file will be located in the /somepath/foo/includes folder. 首先在include_path ,然后PHP将始终首先搜索当前目录,尽管在大多数情况下该文件将位于/somepath/foo/includes文件夹中。

If you don't specify . 如果你没有指定. at the beginning of your include path and use ./abc.php explicitly when you are including a file from the current directory (special case, not one of your “normal” includes), then for all other of your include files that you just include using baz.php , xzy.php and 123.php , PHP will not have to search the current directory first – which is useless, since those files are located in your special include folder; 在包含路径的开头,当你从当前目录中包含一个文件时,显式地使用./abc.php (特殊情况,不是你的“普通”包含的那个),那么对于你刚才的所有其他包含文件包括使用baz.phpxzy.php123.php ,PHP将不必首先搜索当前目录 - 这是无用的,因为这些文件位于您的特殊包含文件夹中; so PHP can go look there in the first place. 所以PHP可以首先看看那里。

It is talking about dot at the begining in the include_path. 它正在讨论include_path开头的dot。

Form PHP Documentation : If filename begins with ./ or ../, it is looked only in the current working directory. 表单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. 'more efficient' means that it better to set path in such way with dot. “更高效”意味着用dot设置路径更好。 In other way it will try to find not only in the current working directory. 换句话说,它不仅会尝试在当前工作目录中查找。 So, it can be a problem if you want to include file in the some directory, but the file is not exist, it will try to find in other path, and it can take some time and make wrong include or just an error. 因此,如果您想要在某个目录中包含文件,但是该文件不存在,它会尝试在其他路径中查找,并且可能需要一些时间并且包含错​​误或仅包含错误,这可能是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM