I'm sure I'm just being a bit stupid, but the include_path
docs seem to be a bit confusing; 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. 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?
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. 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 .
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.
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; so PHP can go look there in the first place.
It is talking about dot at the begining in the include_path.
Form PHP Documentation : 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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.