Bug #9673 Updated: Relative paths in require(), require_once(), include(), include_once()
| From: | vvo at geocities dot com | Date: | Tue, 05 Mar 2002 05:33:03 +0000 |
| Subject: | Bug #9673 Updated: Relative paths in require(), require_once(), include(), include_once() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-1656@lists.php.net to get a copy of this message | ||
ID: 9673
Updated by: vvo@geocities.com
Reported By: vvo@geocities.com
-Status: Closed
+Status: Open
Bug Type: Scripting Engine problem
-Operating System: RedHat Linux 7.0
+Operating System: RedHat Linux 7.1
-PHP Version: 4.0.1pl2
+PHP Version: 4.1.1
New Comment:
I was happy for awhile, but eventually I noticed a problem with *some*
relative paths (in version 4.1.1).
Say, there is the main script 'test.php' and two other files, 'a.inc'
and 'b.inc' (in subdirs):
File './test.php':
<?php
require_once( 'include/a/a.inc' );
?>
File './include/a/a.inc':
<?php
require_once( '../b.inc' );
echo 'a.inc ';
?>
File './include/b.inc':
<?php
echo 'b.inc ';
?>
Running 'test.php' fails with:
Fatal error: Failed opening required '../b.inc'
(include_path='.:/usr/local/lib/php')
in /home/geeba/include/a/a.inc on line 2
This isn't intended, is it?
Thank you!
Previous Comments:
------------------------------------------------------------------------
[2001-07-16 12:07:02] zeev@php.net
include() (and the other functions in its family) will now also look in
the current executing file's directory, so this issue should be
resolved.
------------------------------------------------------------------------
[2001-03-15 10:09:07] vvo@geocities.com
We are talking about all four functions here, not just include(). The
resemblance of require() to the #include directive, as documented:
<quote>The require() statement replaces itself with the specified file,
much like the C preprocessor's #include works.</quote>
If it's a "known issue", are there any plans to fix it?
Thanks.
------------------------------------------------------------------------
[2001-03-15 09:08:11] stas@php.net
First, PHP include() is in no way related or was promised to
relate to C preprocessor directives, so no wonder it behaves
differently.
Now, all relative pathes are resolved against the current
directory of the including script (which is the directory
where it's located). This is a known issue. Use
include_pathes in the meantime.
------------------------------------------------------------------------
[2001-03-10 16:45:48] vvo@geocities.com
Here is an example of how relative paths are currently resolved with
cascading inclusions (command line is 'php /home/joe/a.php'):
File '/home/joe/a.php':
<?php
# this include works as expected,
# locating '/home/joe/include/b.inc'
include_once( 'include/b.inc' );
?>
File '/home/joe/include/b.inc':
<?php
# this include will assume '/home/joe/c.inc', but
# not '/home/joe/include/c.inc', as one may expect =(
include_once( 'c.inc' );
?>
File '/home/joe/include/c.inc':
<?php
echo 'hello';
?>
The way all four functions [require(), require_once(), include(),
include_once()] resolve relative paths is counter-intuitive and
unproductive with large directory structures, because some trickery is
required to fix this problem. Not to mention that it hurts to see a
different behavior from C-preprocessor #include directives.
If you don't believe me, then see comments to the include() function...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=9673&edit=1