Hi All,

while I'm struggling with making a pear package available to my script, it occurred to me that I don't know what the various . / : etc mean when defining a path.

for example, what is the difference between:

include ('/directory/fileA.inc.php?);
include ('./directory/fileA.inc.php');
include ('../directory/fileA.inc.php?);

and in a php.ini directive i've also seen the use of . and : together -
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/my_cPanel_username/pear";

can you please clarify how it works?

thanks,
Patrick

    ./foo/bar.php means look in the directory called "foo" right under the current working directory (the "." character).

    ../foo/bar.php means to look in the directory called "foo" under the parent directory of the current working directory. You can chain multiple "../" together to move further and further up the directory tree.

    /foo/bar.php means to look in the directory called "foo" at the very top of the directory tree, "/" being the root directory of the current logical drive (like "C:\" in Windoze).

    As far as the ":", it's a path separator when defining the include_path. In Windoze you use ";", instead. You can use PHP's PATH_SEPARATOR constant instead so you don't have to worry about which platform you are on:

    set_include_path("/some/new/path" . PATH_SEPARATOR . get_include_path());
    

      When you see the : in PHP.ini, it is being used as a delimiter to separate multiple different paths. When PHP tries to [man]include[/man] some file:

      include 'foo.php'

      Then it will search in a bunch of different places for that file. I'm not sure what the exact sequence is, but I believe it will first search relative to the current working directory (usually the directory of the PHP file being executed), then relative to the file that does the include (keep in mind that included files can themselves include other files), then it will search all those directories in the include_path. Here's what the documentation says:

      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 for only in the current working directory or parent of the current working directory, respectively.

      You can find out what the current include path is using this:

      $var = ini_get('include_path');

      It will return a string that contains a list of directories where PHP will search when trying to include a file.

      On my machine, it returns this:

      .:/usr/share/pear

      If I list the contents of /usr/share/pear, I can see all the pear stuff is in there:

      [root@machine ~]# ls -l /usr/share/pear
      total 108
      drwxr-xr-x  2 root root  4096 Oct 12  2007 Archive
      drwxr-xr-x  2 root root  4096 Oct 12  2007 Console
      drwxr-xr-x  3 root root  4096 Oct 12  2007 data
      drwxr-xr-x  3 root root  4096 Oct 12  2007 doc
      drwxr-xr-x  2 root root  4096 Oct 12  2007 OS
      drwxr-xr-x 11 root root  4096 Oct 12  2007 PEAR
      -rw-r--r--  1 root root 14778 Jan  6  2007 pearcmd.php
      -rw-r--r--  1 root root 34264 Jan  6  2007 PEAR.php
      -rw-r--r--  1 root root  1800 Jan  6  2007 peclcmd.php
      -rw-r--r--  1 root root 19369 Jan  6  2007 System.php
      drwxr-xr-x  3 root root  4096 Oct 12  2007 test
      drwxr-xr-x  3 root root  4096 Oct 12  2007 XML
      
        Write a Reply...