note 44849 added to function.include
| From: | douglass_davis at earthlink dot net | Date: | Wed, 18 Aug 2004 03:33:46 +0000 |
| Subject: | note 44849 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74844@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44849
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44849&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44849&report=yes
Search -- http://master.php.net/manage/user-notes.php