php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37847 require_once does not include files with same name,but are in other locations
Submitted: 2006-06-19 12:24 UTC Modified: 2006-06-19 12:29 UTC
From: rblanker at xs4all dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Linux Fedora 4
Private report: No CVE-ID: None
 [2006-06-19 12:24 UTC] rblanker at xs4all dot nl
Description:
------------
require_once() (probably include_once() too, haven't tested) does not include files in 2 different directories when both files have the same filename (but are 2 different files in 2 different paths);

require_once() stores what is given and skips any require_once() with the same input, not matter what the location is where require_once() was called. It should store/compare the complete path of the included file, not the input.

The workaround is now by specifing the whole path;
require_once($_SERVER["DOCUMENT_ROOT"] . "/toinclude.php");


Reproduce code:
---------------
create 4 files;

/index.php:
<?
print "this is /index.php\n";
require_once("toinclude.php");
require_once("bug/index.php");
?>

/toinclude.php:
<?
print "this is /toinclude.php\n";
?>

/bug/index.php;
<?
print "this is /bug/index.php\n";
require_once("toinclude.php");
?>

/bug/toinclude.php;
<?
print "this is /bug/toinclude.php\n";
?>

Now call '/index.php'

Expected result:
----------------
this is /index.php
this is /toinclude.php
this is /bug/index.php
this is /bug/toinclude.php


Actual result:
--------------
this is /index.php
this is /toinclude.php
this is /bug/index.php


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-19 12:27 UTC] rblanker at xs4all dot nl
Btw; if change /index.php into
/index.php:
<?
print "this is /index.php\n";
//require_once("toinclude.php"); removed.
require_once("bug/index.php");
?>

The new output will show;
this is /index.php
this is /bug/index.php
this is /bug/toinclude.php
 [2006-06-19 12:29 UTC] rblanker at xs4all dot nl
Hmm I now see that the problem is that its included from the path of the /index.php and it does not include from the included file.

The new output will show;
this is /index.php
this is /bug/index.php
this is toinclude.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 18:01:34 2025 UTC