php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27891 Bad behavior of require() function and relative paths with IIS
Submitted: 2004-04-06 14:54 UTC Modified: 2005-08-07 01:00 UTC
Votes:13
Avg. Score:4.5 ± 0.8
Reproduced:13 of 13 (100.0%)
Same Version:9 (69.2%)
Same OS:7 (53.8%)
From: faraco dot phpbugs at mailnull dot com Assigned:
Status: No Feedback Package: IIS related
PHP Version: 5CVS, 4CVS (2005-06-19) OS: win32
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-04-06 14:54 UTC] faraco dot phpbugs at mailnull dot com
Description:
------------
I have the following file structure (folders in uppercase for better understanding):

DOCROOT
 |
 +- LIB
 |   |
 |   +- functions.php
 |
 +- SUBROOT
     |
     +- index.php
     |
     +- LIB
         |
         +- functions.php


The 'index.php' file uses the require() function to include both 'functions.php' files (that have different contents). When running 'index.php', a "Cannot redeclare function" error occurs.
Pay attention at the error message: the compiler says that the same function is redeclared in the same file on different lines!

Reproduce code:
---------------
DOC_ROOT/LIB/functions.php
--------------------------
<?
echo "Here is DOCROOT\\LIB\\functions.php<br>";

function anyfunction($param)
{
	return $param;
}
?>


DOCROOT/SUBROOT/LIB/functions.php
---------------------------------
<?
echo "Here is DOCROOT\\SUBROOT\\LIB\\functions.php<br>";
?>


DOC_ROOT/SUBROOT/LIB/index.php
------------------------------
<?
require("../lib/functions.php");
require("lib/functions.php");

echo anyfunction("Hello World!");
?>


Expected result:
----------------
Here is DOCROOT\LIB\functions.php
Here is DOCROOT\SUBROOT\LIB\functions.php
Hello World!


Actual result:
--------------
Here is DOCROOT\LIB\functions.php
PHP Fatal error: Cannot redeclare anyfunction() (previously declared in C:\doc_root\lib\functions.php:4) in E:\doc_root\lib\functions.php on line 7 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-06 14:55 UTC] faraco dot phpbugs at mailnull dot com
Sorry. I mistyped the Actual Result. The correct message is:
PHP Fatal error: Cannot redeclare anyfunction() (previously declared in
E:\docroot\lib\functions.php:4) in E:\docroot\lib\functions.php on
line 7
 [2004-04-06 15:10 UTC] faraco dot phpbugs at mailnull dot com
The same script runs perfectly on PHP 4.3.4.
 [2004-04-06 15:21 UTC] faraco dot phpbugs at mailnull dot com
Here is the confirmation of the bug. Changing index.php to:
<?
echo realpath("../lib/functions.php")."<br>";
echo realpath("lib/functions.php");
?>

Expected result is:
E:\docroot\lib\functions.php
E:\docroot\subroot\lib\functions.php

While actual result is:
E:\docroot\lib\functions.php
E:\docroot\lib\functions.php
 [2004-09-24 18:35 UTC] kj at legalizer dot dk
What if you turn off ISAPI caching?
 [2005-05-16 22:07 UTC] faraco dot phpbugs at mailnull dot com
I've disabled ISAPI cache and the problem persists.
 [2005-05-16 22:34 UTC] faraco dot phpbugs at mailnull dot com
Another way to explain the problem...

Following de example above:

1. when I require 'lib/functions.php', the file is first looked in my domain document root ['docroot/lib/'] and then in my actual path ['subroot/lib'] because if I delete the first directory, the same script finds the second directory;

2. Yes, my 'include_path' is set to '.';

3. Again, ISAPI Caching is disabled.
 [2005-05-17 16:46 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-05-17 22:54 UTC] faraco dot phpbugs at mailnull dot com
The problem persists.
 [2005-07-30 15:29 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-08-07 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-10-03 13:24 UTC] david_amer at yahoo dot co dot uk
I was having the same problem so i tryed the latest build as sugested in the previous post, it still isnt working unfortunatly.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 16:03:34 2021 UTC