php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46648 Cannot redeclare declared function
Submitted: 2008-11-22 22:48 UTC Modified: 2011-04-08 20:53 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: satovey at yahoo dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 OS: Win98
Private report: No CVE-ID: None
 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-23 15:14 UTC] crrodriguez at opensuse dot org
XAMMP includes Zend Optimizer and possible other zend extensions, please disable all zend extensions and report back if the problem still exists.
 [2008-11-25 15:21 UTC] satovey at yahoo dot com
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
 [2008-12-16 16:01 UTC] zyss at mail dot zp dot ua
include_once can be used instead of include (in this case) - file will not be included twice so there will be no errors about the function redeclaration.
 [2011-04-08 20:53 UTC] jani@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2011-04-08 20:53 UTC] jani@php.net
Chose option 1.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 13:00:02 2025 UTC