|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43821 require_once is case sensitive
Submitted: 2008-01-11 15:59 UTC Modified: 2008-07-11 21:32 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: wxjasp02 at smumn dot edu Assigned:
Status: Wont fix Package: Streams related
PHP Version: 4.4.8 OS: Windows Server 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: wxjasp02 at smumn dot edu
New email:
PHP Version: OS:


 [2008-01-11 15:59 UTC] wxjasp02 at smumn dot edu
Require_Once in PHP 4.4.7 appears to be case sensitive in checking files already included.

This has triggered 'cannot redeclare class' in situations where a classfile may be already loaded, but require_once doesn't see it.

In light testing, I have found that I have to force my code to switch any include or require calls to lower case to avoid this.

I realize this is an old version of php, and 4 is officially 'dead'; but I am unaware if this has been fixed. (I wouldn't use 4, however the site where we host refuses to move to PHP5 or update php4 to the latest.)

The bug was originally identified in Version 4.3.4, see: Bug# 26552; however I believe it has re-surfaced.

System Configuration:
Windows Server 2003
Apache 2.0.59
PHP 4.4.7

Reproduce code:
Make a class and put it in a file which you will require_once.
<?php class MyClass {} ?>

In the file you will run, call:
$obj = new MyClass();

require_once('MyClass.php'); // Will trigger an error
// because MyClass cannot be redeclared; however myclass.php 
// is being loaded TWICE

Expected result:
The expected result is to only load myclass.php ONCE.

To confirm the problem, empty the file myclass.php, or put some non-class junk in it.

After each require_once, add:   print_r(get_included_files());

You should see myclass.php the first time it is called,
and myclass.php, MyClass.php, the second.

Actual result:
Cannot Redeclare class MyClass in ... on line ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-11 21:32 UTC]
We are sorry, but we can not support PHP 4 related problems anymore.
Momentum is gathering for PHP 6, and we think supporting PHP 4 will
lead to a waste of resources which we want to put into getting PHP 6

 [2014-08-18 22:04 UTC] jonathan dot rodan at gmail dot com
This problem was causing the require_once to include a file twice.

I was using apache and I found that the __DIR__ of the executed file was the same one found in the DOCUMENT_ROOT of the apache config.

That means that if the apache config had

DocumentRoot /users/me/stuff/my_site
script from the question was printing:

PATH = /users/me/stuff/my_site (All lower case)

PATH = /Users/me/stuff/my_site (Mixed case)
And if the apache config had:

DocumentRoot /Users/me/stuff/my_site
script from the question was printing:

PATH = /Users/me/stuff/my_site (Mixed case)

PATH = /Users/me/stuff/my_site (Mixed case)
Which was much better.

If you encounter this problem, check the apache configuration taking into account that it's case sensitive.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 18 18:01:26 2020 UTC