What is the difference between relative paths "./file" and "file"

I always see developers, including external files, using these two types of relative paths. The question is, is there a difference between "

require "./lib/helpers.php"

and

require "lib/helpers.php"

As far as I know, both points point to the same file. But is anyone superior in terms of complexity?

Hello

+4
source share
1 answer

./lib/...binds an include request in the current working directory of the script. PHP will search for the desired file there, and not somewhere else. If it does not exist, inclusion and inclusion are not performed.

lib/...allows PHP to scan its inclusion path, for example. if you have

include_path=.:/var/lib/php:/foo/bar/baz

Then PHP will sequentially try to execute

           ./lib/file.php
/var/lib/php/lib/file.php
/foo/bar/baz/lib/file.php
^^^^^^^^^^^^---- include path component
             ^^^^^^^^^^^^--- include() argument

, . , , .

+6

All Articles