#40666 [NEW]: handling of relative paths in include()

From: Date: Wed, 28 Feb 2007 12:39:25 +0000
Subject: #40666 [NEW]: handling of relative paths in include()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-109704@lists.php.net to get a copy of this message
From: mfr at bmx-chemnitz dot de Operating system: all PHP version: 5.2.1 PHP Bug Type: Feature/Change Request Bug description: handling of relative paths in include() Description: ------------ To start with, PHP version is irrevelant for this request, regardless what your bug report form says. This is Change Request. Change the way relative includes are handled. The current way of NOT using the script directory but the current working directory, while documented, cannot be considered a feature but is clearly a bug. A script should NOT have to worry about where it was included from when it needs to include other files, regardless of the way it includes them (relative, absolute, relative with "./" / "../"). The way this is implemented generates confusion and, quite frankly, breaks stuff. Pushing responsibility to properly deal with basic functionality like this to the user is just wrong. Following this up with an intended reply to bug #22865: I am sorry, but how can this not be a bug? You say the documentation says that "Relative paths in include/require are always relative to the initial script, *not* to the file doing the include-ing." Which, regarding the state of documention, is all fine and well, given that the documentation describes the wrongness of the behaviour correctly. HOWEVER, the behaviour itself is the bug. How can it be intended that, in any given file, any relative include has to know where the originally called file is located? Why should it care? How would it know? If I have a file x that just knows it needs file y in the parent directory, then this is all there should be to it. You claim that "You will need to use some kind of tracking of the base path for the current invocation.". Pardon me, but this is exactly the kind of house-keeping that include() itself is supposed to do. Reproduce code: --------------- foo/bar.php: <?php echo "foo/bar.php "; include("../baz.inc"); ?> baz.inc: <?php echo "baz.inc "; ?> index.php: <?php echo "index.php "; include("foo/bar.php"); ?> Expected result: ---------------- http://host/foo/bar.php "foo/bar.php baz.inc" http://host/index.php "index.php foo/bar.php baz.inc" Actual result: -------------- http://host/foo/bar.php "foo/bar.php baz.inc" http://host/index.php "index.php foo/bar.php Warning: main(../test.inc) [missing file...]" -- Edit bug report at http://bugs.php.net/?id=40666&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40666&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40666&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40666&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40666&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40666&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40666&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40666&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40666&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40666&r=support Expected behavior: http://bugs.php.net/fix.php?id=40666&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40666&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40666&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40666&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40666&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40666&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40666&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40666&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40666&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40666&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40666&r=mysqlcfg

« previous php.bugs (#109704) next »