ID:               46648
 Comment by:       zyss at mail dot zp dot ua
 Reported By:      satovey at yahoo dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Win98
 PHP Version:      5.2.6
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-11-25 15:21:25] 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-11-23 15:14:01] 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-22 22:57:20] lbarn...@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



------------------------------------------------------------------------

[2008-11-22 22:48:54] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46648&edit=1

Reply via email to