php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46395 Inconsistent behaviour of require_once
Submitted: 2008-10-26 18:15 UTC Modified: 2009-01-29 01:00 UTC
Votes:19
Avg. Score:4.6 ± 0.7
Reproduced:18 of 18 (100.0%)
Same Version:11 (61.1%)
Same OS:10 (55.6%)
From: ebosman at gmail dot com Assigned:
Status: No Feedback Package: Directory function related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
 [2008-10-26 18:15 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-26 18:57 UTC] jani@php.net
Put 'echo getcwd(), "\n";' to each file before the require line.
 [2008-10-26 19:32 UTC] 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-11-24 09:52 UTC] jani@php.net
Try removing the . from your include_path setting.
 [2008-11-24 17:15 UTC] ebosman at gmail dot com
Same result:

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

top.php:

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 2

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 2
 [2008-11-24 17:30 UTC] ebosman at gmail dot com
correction, for top.php it should be (still no difference):

/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

(line difference in the previous comment was because of copy-pasting)
 [2008-11-24 17:33 UTC] ebosman at gmail dot com
And then I forgot that I put the original include_path back, apologies

/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
 [2008-12-09 20:30 UTC] tomas at matfyz dot cz
Note that my bug #46801 was marked as a duplicate of this one. My testcase could be found here: http://tomas.matfyz.cz/obs/pok_require_dirs3/report/www/use.php
 [2009-01-21 19:47 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-01-29 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".
 [2009-03-31 08:26 UTC] befroozfar at yahoo dot com
Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in
 [2012-07-02 11:15 UTC] ebosman at gmail dot com
The code snippet in the bug report still reproduces the bug.
Why are bugs not being tested and closed when the reports
contain easy test cases?

Also, why am I not able to re-open this thing
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC