php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33099 Relative paths in require(), require_once(), include(), include_once()
Submitted: 2005-05-22 09:47 UTC Modified: 2005-05-30 01:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: blue2 at hat dot net Assigned:
Status: No Feedback Package: Feature/Change Request
PHP Version: 5.0.3 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: blue2 at hat dot net
New email:
PHP Version: OS:

 

 [2005-05-22 09:47 UTC] blue2 at hat dot net
Description:
------------
Relative paths in require(), require_once(), include(), include_once() does not resolve correctly (i.e. relative to the file that reference the script, not the file that execute the script).

Reproduce code:
---------------
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.

Expected result:
----------------
When a.inc include "../b.inc", it should reference from the location of ./include/a/a.inc, not the executing file, ./test.php.

This happens on both Windows XP and UNIX (Red Hat Linux), and probably all other platforms (which I can't verify).

This really hurt modularity.

I know this is not consider a bug, but would you improve this please? (like adding a realtive_include() function would really be nice)

Actual result:
--------------
Fatal error: main() [function.require]: Failed opening required '../b.inc' (include_path='.;C:\php5\pear') in XXXXX on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, 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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC