|  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
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-03-23 09:12 UTC] lodder at yacc dot com dot au
when using include, __FILE__ prepends / to relative paths

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 =>

  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 => 

    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 
The output 
/home/gedl/tmp $ gcc -o a a.c ./lib/b.c && echo "The output" && ./a 
The output 
/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.




Add a Patch

Pull Requests

Add a Pull Request


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]
Please try using this CVS snapshot:
For Windows:

 [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: Sun Jun 16 18:01:30 2024 UTC