note 44849 deleted from function.include by betz
| From: | betz@php.net | Date: | Wed, 18 Aug 2004 06:57:30 +0000 |
| Subject: | note 44849 deleted from function.include by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74864@lists.php.net to get a copy of this message | ||
Note Submitter: douglass_davis at earthlink dot net
----
The manual for include says:
1) Files for including are first looked in include_path relative to the current working directory
and 2) then in include_path relative to the directory of current script
however, #2 is not true if you are using a relative path, in addition, the include_path is not
searched when using a relative path. I found this to be somewhat confusing. For example:
lets say you have a library that many other files must use.
The library is htdocs/mylib/lib_one.php
lib_one attempts to include htdocs/lib_two.php:
include('../lib_two.php'); // uses relative path
In htdocs/index.php, I include lib_one.php. I expected lib_one to then include htdocs/lib_two.php,
but that was not the case.
I then found out that the only place that it looks for lib_two is in htdocs/../lib_two.php (aka
Apache/ ).
So the point:
1. when using relative paths, the include_path is not searched
2. when using relative paths, they are relative ONLY to the current working directory, not relative
to the current script.
3. use include(dirname(__FILE__).'../lib.php'); when using relative paths, because
include('../lib.php'); doesn't work as expected when the current script was included
from a file in another directory (current working directory is not the same as directory of current
script).
I'm using PHP 4.3.7 on Apache 1 on Win XP Professional