簡體   English   中英

PHP的include_path設置

[英]PHP's include_path setting

我確定我只是有點愚蠢,但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. 

實際上想說?

什么是

用一個 。 在include路徑中允許相對包含,因為它表示當前目錄。 但是,顯式使用include'。/ file'比讓PHP始終檢查每個include的當前目錄更有效。

實際上想說?

假設您未在顯式指定路徑時使用include_path在文件夾/somepath/foo/includes搜索包含文件。 你可能有大部分的包含文件,所以這應該不是太低效。

現在你要從該目錄中包含baz.phpxzy.php123.php - 如果你已經給出了. 首先在include_path ,然后PHP將始終首先搜索當前目錄,盡管在大多數情況下該文件將位於/somepath/foo/includes文件夾中。

如果你沒有指定. 在包含路徑的開頭,當你從當前目錄中包含一個文件時,顯式地使用./abc.php (特殊情況,不是你的“普通”包含的那個),那么對於你剛才的所有其他包含文件包括使用baz.phpxzy.php123.php ,PHP將不必首先搜索當前目錄 - 這是無用的,因為這些文件位於您的特殊包含文件夾中; 所以PHP可以首先看看那里。

它正在討論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設置路徑更好。 換句話說,它不僅會嘗試在當前工作目錄中查找。 因此,如果您想要在某個目錄中包含文件,但是該文件不存在,它會嘗試在其他路徑中查找,並且可能需要一些時間並且包含錯​​誤或僅包含錯誤,這可能是一個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM