|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-11-22 22:48 UTC] satovey at yahoo dot com
Description:
------------
PHP seems to think that a function is redeclared.
1) This is the first function declared.
2) This is not occurring with any other declared functions.
3) This error occurs even when the entire function is placed
on a single line.
4) The error occurs on this function call whether it is in
the given file or inside an include file.
Reproduce code:
---------------
This is the system
Win98 running the following.
Apache Version
Apache/2.2.9 (Win32)
DAV/2 mod_ssl/2.2.9
OpenSSL/0.9.8h mod_autoindex_color
PHP/5.2.6
xampp version Version 1.6.7
Here is the error message.
Fatal error: Cannot redeclare getadminmodules()
(previously declared in
C:\xampp\htdocs\oldwebsite\YevotasSite\YevotasSite.php:26)
in C:\xampp\htdocs\oldwebsite\YevotasSite\YevotasSite.php on
line 26
Code for line 26 is as follows:
function getadminmodules(){}
Expected result:
----------------
The syntax is correct and therefore no errors are expected.
Actual result:
--------------
Fatal error occurs.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 08:00:01 2025 UTC |
112508 Last night while trying to create a stripped down version of my script so that you guys could recreate the bug, I discovered what was actually causing it and it was not anything that was suggested. This turns out to not be an issue with the interpreter or zend framework but the way errors are reported. To recreate this error you need to do the following: 1) You will need three files. testbug.php, testincl1.php, testincl2.php create a directory called testdir and put testincl1.php and testincl2.php within it. 2) Within testbug.php put the following code: //error reporting ini_set('display_errors', '1'); error_reporting(E_ALL); include("testdir/testincl1.php"); include("testdir/testincl2.php"); 3) Within testincl1.php put the following code. echo "testincl1.php<br>"; include ("testincl2.php"); At this point, you may already see the problem. If not step 4 will enlighten you :) 4) Within testincl2.php put the following code. echo "testincl2.php<br>"; function testfunc(){echo "testfunction<br>";} testfunc(); The reason I didn't immediately catch this is due to the fact that in my main file which calls include2.php the second time is that the command is on line 161 So the real issue is not an engine bug but an error reporting bug. *** Solutions *** Because the error does not refer to the two seperate include commands for testincl2.php, the error is obscure and hard to find. There are three ways to handle this issue. 1) Do nothing as it is a bug in the programmers code and has nothing to do with PHP. That's the easy way out but you'll keep getting these bugs reported when they for apparent reason occur. 2) Change the debugger so that it refers to both include commands and where they are located. 3) The best approach is to implement a new programming rule for includes. As no two functions can have the same name, neither should any two directory/includefile.php bare the same name. Under this rule ** Allowed ** /dir1/includefile.php and /dir2/includefile.php would be allowed because they reside under two different directories. This is desirable as it is necessary for templates and themes to work properly. ** Not Allowed ** include ("dir/includefile.php") include ("dir/includefile.php") would not be allowed as they are the same file within the same directory. include ("dir/includefile2.php") within the index.php file and /dir2/includefile.php which contains include ("includefile2.php") would not be allowed as they are the same file within the same directory. In this way, an error message would point to both include instances and what line they occur on. If the same bug in other versions have not been found out, this is most likely what caused them. Following either suggestion two or three and patching previous versions to correct the issue will take care of it permanently. Take care. Scott