php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16231 when using include, __FILE__ prepends / to relative paths
Submitted: 2002-03-23 09:12 UTC Modified: 2002-10-14 19:26 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: lodder at yacc dot com dot au Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 4.1.2 OS: HP-UX 11.0
Private report: No CVE-ID: None
 [2002-03-23 09:12 UTC] lodder at yacc dot com dot au
Summary:
when using include, __FILE__ prepends / to relative paths

History:
Received errors from imp3.0 saying could not find included file. Error message reported strange path names. See Horde bugs #911 and #912.

Sample Code:
a.php =>

<?php 
  echo "Calling  file ", __FILE__; 
  echo "<br>included as lib/a.php reports "; 
  include 'lib/a.php'; 
  echo "<br>included as ./lib/a.php reports "; 
  include './lib/a.php'; 
  echo "<br>included as /www/yacc/tmp/lib/a.php reports "; 
  include '/www/yacc/tmp/lib/a.php'; 
?> 

lib/a.php => 

<?php 
    echo  __FILE__; 
?> 

When I do this, I get 

Calling file /www/yacc/tmp/a.php 
included as lib/a.php reports /lib/a.php 
included as ./lib/a.php reports /lib/a.php 
included as /www/yacc/tmp/lib/a.php reports /www/yacc/tmp/lib/a.php 

Something keeps putting a leading / on relative paths!

Other Tests:

I created a simple C program to print out the __FILE__ value. When is compile it with HP's ANSI C compiler it works as expected i.e. the value is as specified in the include. When I compile with GNU CC compiler (gcc) the value is "sanitised". 
 
See below 

/home/gedl/tmp $ cc -o a a.c ./lib/b.c && echo "The output" && ./a 
a.c: 
./lib/b.c: 
The output 
a.c 
./lib/b.c 
/home/gedl/tmp $ gcc -o a a.c ./lib/b.c && echo "The output" && ./a 
The output 
a.c 
lib/b.c 
/home/gedl/tmp $ 
 
Essentially the same but not exactly. However both compilers give a valid answer.

I will continue to work on it but if someone has an answer it would be appreciated.

Cheers

Ged

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-04 00:27 UTC] lodder at yacc dot com dot au
Had some feedback from Scott Kearney from Harvard Uni:-

He also experienced this on an OSF/1 platform. One of his colleagues traced this to a directory permissions issue.

It appears that if a higher level directory has execute permission but not read permission, this problem appears.

Changing the higher level directories to permission 555 fixed this. This is a good workaround but I don't want to compromise my system security to get an application to work ;-)

Thanks to Scott and his colleagues for their input.
 [2002-09-28 17:11 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-10-14 19:26 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 05 22:01:28 2024 UTC