当文件存在于路径和本地目录中时,将包含哪个文件?

发布于 2024-10-21 09:38:39 字数 153 浏览 1 评论 0原文

如果我的路径中有一个名为 inc.php 的文件,而另一个名为 inc.php 的文件位于与 index.php 相同的目录中,并且在 index.php 中我放置了

include('inc.php')

哪个文件将被包含?

If I have a file in the path called inc.php and another file called inc.php in the same directory as index.php, and in index.php I place

include('inc.php')

Which file will be included?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夢归不見 2024-10-28 09:38:40

当您执行包含时,PHP 会搜索包含路径中的每个条目,检查文件是否存在,直到找到它为止,然后将来自该条目的文件包含在包含路径中。

通常,包含路径具有 . (当前工作目录)作为其第一个条目。

因此,除非您更改了 include_path,以便 .不再是第一个条目,它将包含当前工作目录中的文件因为它也是在 include_path 中找到的文件的第一个副本。

When you do an include, PHP searches through each entry in the include path checking for the existence of the file until it finds it, whereupon it includes the file from that entry in the include path.

Typically, the include path has . (the current working directory) as its first entry.

So unless you've changed the include_path so that . is no longer the first entry, it will include the file from the current working directory because it's also the first copy of the file that it finds in the include_path.

萌能量女王 2024-10-28 09:38:40

PHP 将从左到右遍历您的包含路径,并针对每个文件夹检查该文件夹中是否存在这样命名的文件。

它将包括它找到的第一个。

如果您包含的路径类似于 ".:/some/dir/:/some/other/dir" ,它将首先在当前文件夹中查找。然后检查其他的,如果没有发现任何东西。

因此通常它会将文件包含在同一文件夹中。

要查看包含路径,请使用 (fe) echo ini_get("include_path");

PHP will go over your include path from left to right and for every folder check if a file named like this exists in that folder.

It will include the first one it finds.

If you include path looks like ".:/some/dir/:/some/other/dir" it will look in the current folder first. Then check the others if it doesn't find anything.

So usually it will include the file in the same folder.

To see what your include path looks like use (f.e.) echo ini_get("include_path");

七七 2024-10-28 09:38:40

include() 函数中可以找到文档:

如果在目录中找不到该文件
include_path, include() 最终会
检查调用脚本自己的
目录和当前工作
失败之前的目录。

因此,首先搜索 include_path 然后搜索当前目录(但是如果里面有 . ,你的 include_path 可能会包含当前目录,甚至可能先搜索这取决于您的服务器配置)。

As could be found in the include() function documentation :

If the file isn't found in the
include_path, include() will finally
check in the calling script's own
directory and the current working
directory before failing.

So the include_path is searched first then the current directory (But your include_path could include the current directory if there is a . inside, maybe even first it depends on your server configuration).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文