|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-11-24 14:25 UTC] ovdspek at liacs dot nl
Description:
------------
In PHP, includes (appear to) use the current working directory. In C++, includes use the directory of the including script (and the include path).
Could the C++ behaviour be added to PHP includes?
Because if relative includes are used, current PHP scripts can only be executed if cwd == script dir.
Reproduce code:
---------------
$ cat 1.php
<?php
echo "1.php<br>\n";
?>
$ cat b/2.php
<?php
include('../1.php');
?>
$ php -f b/2.php
Warning: main(../1.php): failed to open stream: No such file or directory in /home/olaf/t/a/b/2.php on line 2
Warning: main(): Failed opening '../1.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/olaf/t/a/b/2.php on line 2
$ cd b
$ php -f b/2.php
Could not open input file: b/2.php.
$ php -f 2.php
1.php<br>
$
Expected result:
----------------
Warning: main(../1.php): failed to open stream: No such file or directory in /home/olaf/t/a/b/2.php on line 2
Warning: main(): Failed opening '../1.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/olaf/t/a/b/2.php on line 2
Actual result:
--------------
1.php<br>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
> Current working directory can be something different than directory of a script. I understand, but apparently your implementation doesn't. Why else would "include('../1.php');" fail?