php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49456 Script current working directory converted to real path cause require() errors
Submitted: 2009-09-03 14:36 UTC Modified: 2009-09-03 14:45 UTC
From: michele dot manzato at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.11RC1 OS: Ubuntu/Hardy
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: michele dot manzato at gmail dot com
New email:
PHP Version: OS:

 

 [2009-09-03 14:36 UTC] michele dot manzato at gmail dot com
Description:
------------
PHP script current working directory being converted to the real path cause error in relative files inclusion (see also bug #46814).

As one can see in the reproduce code the script's getcwd() says '/tmp/a' although the script was run from '/tmp/b/c'. As a result the require() instruction fails because it can't find any '/inc.php'. '/tmp/b/inc.php' would have been found if the original symlinked path was preserved.

Reproduce code:
---------------
~$ cd /tmp
/tmp$ mkdir a
/tmp$ mkdir b
/tmp$ echo '<?php echo getcwd(); require "../inc.php";?>' > a/test.php
/tmp$ echo '<?php echo "ok\n";?>' > b/inc.php
/tmp$ ln -s /tmp/a b/c
/tmp$ cd b/c/
/tmp/b/c$ php -f test.php





Expected result:
----------------
ok

Actual result:
--------------
/tmp/a
Warning: require(../inc.php): failed to open stream: No such file or
directory in /tmp/a/test.php on line 1

Fatal error: require(): Failed opening required '../inc.php' (include_path='.:/usr/share/php:/usr/share/pear') in /tmp/a/test.php on line 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-03 14:45 UTC] sjoerd@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Note that this behavior is the same as in a shell:
cd b/c
ls ..

It shows the contents of /tmp, not the contents of /tmp/b. This works as it should.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC