点斜线对 PHP 包含调用有何作用? [英] What does the dot-slash do to PHP include calls?
问题描述
A.这是做什么的?
require ("./file.php");
B.相比之下?
require ("file.php");
<小时>
(它不是向上一个目录......这将是)
(Its not up-one-directory.. which would be)
require ("../file.php");
推荐答案
./
是 当前 目录.它与 file.php
大致相同,但在许多情况下(包括这个),它不检查 PHP 可能查找文件的任何标准位置,而是检查只 当前目录.
./
is the current directory. It is largely the same as just file.php
, but in many cases (this one included) it doesn't check any standard places PHP might look for a file, instead checking only the current directory.
来自 PHP 文档(注意最后一句):
From the PHP documentation (notice the last sentence):
要包含的文件首先在相对于当前工作目录的每个 include_path 条目中查找,然后在当前脚本的目录中查找.例如.如果您的 include_path 是库,当前工作目录是/www/,您包含了 include/a.php 并且该文件中有包含b.php",则首先在/www/libraries/中查看 b.php,然后在/www/包括/.如果文件名以 ./或 ../开头,则仅在当前工作目录中查找.
Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.
这篇关于点斜线对 PHP 包含调用有何作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!