php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52838 include/require problems with ../
Submitted: 2010-09-14 11:18 UTC Modified: 2010-09-14 11:21 UTC
From: winzent at gmail dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.3.3 OS: WinXP maybe others
Private report: No CVE-ID: None
 [2010-09-14 11:18 UTC] winzent at gmail dot com
Description:
------------
So here is the layout of my files:

B.php
page/1.php
page/A.php
page/mod/2.php

1 and 2 are pages that are used independently.
A and B are included files with classes and functions.
1 includes A which includes B
2 includes A which includes B

This affects the include,include_once,require and require_once functions.
Found this in the 5.2.3 so I upgraded to 5.3.3 and it's still there.
I have WinXP Pro SP3 and use Apache 2.2.4
---
I have come up with a workaround for my site, which is to remove B from A and include B in 1 and 2 and all the other filers in the page/mod/ directory, but that is just a pain when it shouldn't work like this! Right?


Expected result:
----------------
Well I expected both 1 and 2 to work.
I should not have to take in to account where the file that includes my file lies, so 1 and 2 should get the same results.


Actual result:
--------------
The 1,A,B combo works fine.

But the 2,A,B does not. (The B file not found!)

And the thing that goes wrong is when A is to include B with ../B.php it ignores the ../ and just looks in the current directory of A.
After some more testing I found that 1 including 2 including A would result in the same error with the file not being found because it searches in the wrong directory.
So this is similar to the PHP4 error of included files searching from their parents directory instead of their own when trying to further include files, but this only happens when an ../ is involved.

If I put ../../B.php in A then it works in 2, but then 1 tries to go back one directory to much, which it should because that's what's written.
Also /B.php or ./B.php seem to work for 2, but messes things up for 1.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-14 11:21 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-09-14 11:21 UTC] aharvey@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions.

Include paths are relative to the initial working directory -- that's how PHP has always worked. You may wish to investigate the __FILE__ and __DIR__ constants in the manual.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC