|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 18:00:02 2025 UTC |
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