php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33224 require_once includes the same file again even if path/filename is identical
Submitted: 2005-06-02 17:16 UTC Modified: 2005-06-10 01:00 UTC
Votes:6
Avg. Score:4.7 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:4 (66.7%)
From: ypae at hotmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.4 OS: Windows 2003 Server
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ypae at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-06-02 17:16 UTC] ypae at hotmail dot com
Description:
------------
When I created a lib.inc.php that has a few functions defined (e.g. getmicrocode(), myfunction()) and try to include it on several files with require_once, it somehow included more than once even though the end result of 'path/filename' is identical.

My understanding of require_once limitation on Windows (or non-POSIX) platform was that if you have mixed case with the same file name, it will be included again. Another words, as long as you have identical "path/filename" as part of require_once statement, it should include only once.

As a result, since you cannot redeclare the same function within the page, you get:

Fatal error: Cannot redeclare "functionname()" (previously declared in...



Reproduce code:
---------------
For example,

On lib.inc.php:
===============
myfunction1() 
{ echo "hello!";}

myfunction2() 
{ echo "hello again!";}

On index.php 
============
$_my_absolute_path = 'c:/inetpub/wwwroot/';

require_once($_my_absolute_path.'lib.inc.php');
require_once($_my_absolute_path.'template.inc.php');
   
on template.inc.php
===================
$_my_absolute_path = 'c:/inetpub/wwwroot/';

require_once($_my_absolute_path.'lib.inc.php'); // Just in case someone didn't call this previously

The realistic code is quite complex: 
A require_once B and C
B require_once C and *D*
C require_once *D*

and *D* causes redeclare issue when I load A.


Expected result:
----------------
the second attempt to include lib.inc.php by using require_once should be ignored because it was already loaded. 

The same code running on Linux works perfectly and it used to be fine on PHP 4.3.10

But right after I rebuild the server with PHP 5.0.4, I got the following error:

Fatal error: Cannot redeclare myfunction1() (previously declared in...



Actual result:
--------------
the second attempt to include lib.inc.php by using require_once WAS performed and it causes error.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-02 20:40 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2005-06-10 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".
 [2005-08-18 10:39 UTC] matthius at pointbtel dot com
I am experiencing this in v4.4.0 as well.
 [2008-03-29 19:26 UTC] m dot hertzog at mhs dot ch
It's still there in 5.2.5. Seems not to occour if the includes files are specified with full path i.E. require_once(c:\www\test.com\docs\tobeincluded.php);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC