#46395 [Opn->Fbk]: Inconsistent behaviour of require_once
| From: | jani@php.net | Date: | Mon, 24 Nov 2008 09:52:56 +0000 |
| Subject: | #46395 [Opn->Fbk]: Inconsistent behaviour of require_once | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-131250@lists.php.net to get a copy of this message | ||
ID: 46395
Updated by: jani@php.net
Reported By: ebosman at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Directory function related
Operating System: Linux
PHP Version: 5.2.6
New Comment:
Try removing the . from your include_path setting.
Previous Comments:
------------------------------------------------------------------------
[2008-10-26 19:32:50] ebosman at gmail dot com
I added 'echo __FILE__," ",getcwd(), "\n";' to each line:
mkdir -p bug/subdir
echo '<?php echo __FILE__," ",getcwd(), "\n"; require_once
"../top1.inc"; ?>' > bug/subdir/sub.inc
echo '<?php echo __FILE__," ",getcwd(), "\n"; require_once
"sub.inc";
?>' > bug/subdir/sub.php
echo '<?php echo __FILE__," ",getcwd(), "\n"; require_once
"subdir/sub.inc"; ?>' > bug/top.php
echo '<?php echo __FILE__," ",getcwd(), "\n"; require_once
"top2.inc";
?>' > bug/top1.inc
echo '<?php echo __FILE__," ",getcwd(), "\n"; ?>' >
bug/top2.inc
The output for subdir/sub.php:
/var/www/bug/subdir/sub.php /var/www/bug/subdir
/var/www/bug/subdir/sub.inc /var/www/bug/subdir
/var/www/bug/top1.inc /var/www/bug/subdir
/var/www/bug/top2.inc /var/www/bug/subdir
and for top.php:
/var/www/bug/top.php /var/www/bug
/var/www/bug/subdir/sub.inc /var/www/bug
(and htmlized:)
Warning: require_once(../top1.inc) [function.require-once]: failed to
open stream: No such file or directory in /var/www/bug/subdir/sub.inc on
line 1
Fatal error: require_once() [function.require]: Failed opening required
'../top1.inc' (include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/bug/subdir/sub.inc on line 1
This would be consistent with the first include method
(relative to the original file.) But in that case including
top2.inc should fail, which it doesn't.
------------------------------------------------------------------------
[2008-10-26 18:57:32] jani@php.net
Put 'echo getcwd(), "\n";' to each file before the require line.
------------------------------------------------------------------------
[2008-10-26 18:15:19] ebosman at gmail dot com
Description:
------------
In the code pasted below:
- top.php fails on subdir/sub.inc including "../top1.inc"
- subdir/sub.php doesn't.
Either every include should be relative to the original php file
(which would be braindead, but consistent.) In that case both
php files should fail (for subdir/sub.php the include of top2.inc
by top1.inc should fail.)
Or (and this is what I expected) include files should be relative
to the file that is including. In which case both should succeed.
Probably the same bug as http://bugs.php.net/bug.php?id=38302 , which
is labeled bogus, so I had to create a new one.
Reproduce code:
---------------
mkdir -p bug/subdir
echo '<?php require_once "../top1.inc" ?>' > bug/subdir/sub.inc
echo '<?php require_once "sub.inc" ?>' > bug/subdir/sub.php
echo '<?php require_once "subdir/sub.inc" ?>' > bug/top.php
echo '<?php require_once "top2.inc" ?>' > bug/top1.inc
touch bug/top2.inc
Expected result:
----------------
Neither top.php nor subdir/sub.php should generate errors (or both
should.)
Actual result:
--------------
Warning: require_once(../top1.inc) [function.require-once]: failed to
open stream: No such file or directory in /var/www/bug/subdir/sub.inc on
line 1
Fatal error: require_once() [function.require]: Failed opening required
'../top1.inc' (include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/bug/subdir/sub.inc on line 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46395&edit=1