ID:               18590
 Comment by:       greg at pwsdb dot com
 Reported By:      armageddon at raydan dot de
 Status:           No Feedback
 Bug Type:         Scripting Engine problem
 Operating System: WinXP Pro
 PHP Version:      5.0.0-dev
 New Comment:

PS
This only happened within a checkout page of ZenCart ("part 3 of 3")  
and not another (not the login page) ... I don't know enough about zc
to know what the significant difference is.


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

[2009-02-04 02:59:23] greg at pwsdb dot com

this experience/test may help:

I defined a function (fff) in the top of my pgm. (not in a loop)
it spanned from line 5 to 11 and used it in the code below.  
I got this error msg:


Fatal error: Cannot redeclare fff() (previously declared in 
/.../xxx.php:5) in 
/.../xxx.php on line 11


I then removed it to an external file (xx-functions.php) and did a 
"require_once() for xxx-functions.php on line 6  and got these 2 
error messages where there should have only been one. 
IT WAS TRYING TO LOAD THE FUNCTION(PGM) TWICE: 


Warning: require_once(xxx-functions.php) [function.require-once]: 
failed to open stream: No such file or directory in 
/.../xxx.php on line 6

Fatal error: require_once() [function.require]: Failed opening required

'xxx-functions.php' (include_path='.:/usr/share/pear') in 
/.../xxx.php on line 6

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

[2008-05-30 13:48:47] mark dot php dot net dot special at emceesoftware
dot com

As a followup to my last comment, the way this "error" is being
reported proved a little confusing, and my warrant some minor research
in order to help make it a bit easier to identify when it happens.

My error log reports the following (abbreviated):

PHP Fatal error:  Cannot redeclare simplehtml_rendercontent()
(previously declared in SimpleHTML.php:149) in SimpleHTML.php on line
152

Noteworthy is the fact that the RenderContent() method is declared on
line 149.  The closing brace for the method is on line 152.

It was this difference in line numbers that proved the most confusing. 
If they both reported out at line 149, I suspect I would have more
quickly determined that I was seeing a reload problem of some sort.

Also, if after adjusting the line number being reported, it is
determined that they are identical, it might be helpful to post an
additional line in the error log which suggests the developer look at
replacing an include() with include_once() or require() with
require_once().

With that bit of reporting, I suspect most folks who get bit with this
type of issue will be able to resolve it more quickly (whether
dynamically as I've done, or at the top of a PHP file).

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

[2008-05-30 12:43:13] mark dot php dot net dot special at emceesoftware
dot com

PHP 5.2.4 (Build date 30 Aug 2007)

I experience this error while using a technique for dispatching method
calls dynamically.

On receipt of an XML packet, an API method determines the php module
(source file) that needs to be loaded to process the XML file.

Next, the method name is loaded into a variable, and the source file is
included.

Finally, the variable is used to call the method.

I've been successfully testing this approach for some time, and am
confused as to why it has started "now".

Code sample (abbreviated):

$moduleName = ... (extracted from XML structure)
$methodName = ... (derived from another parameter)
$sourceFile = $_SERVER["DOCUMENT_ROOT"].'/path/'.$moduleName.'.php';
include( $sourceFile );
$dynamicMethod = $moduleName.'_'.$methodName;
$dynamicMethod();  // attempt the call

My theory is that this code is being called multiple times with the
same value for $moduleName, causing the include() method to attempt to
load it multiple times.  While this doesn't seem to be an issue when
using the static 'include_once' declaration, it appears to be an issue
when loading dynamically.

When changing the above code to use include_once(), the problem seems
(so far) to have gone away.

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

[2007-09-03 13:52:58] info at rchu dot nl

update: adding a space to the source results in the same 'cannot
redeclare' error. Only changing the function name resolves the problem
at the fist run. Must be some kind of caching problem I suppose. When
running the script on the command line there is no problem, just when I
request in in my browser. I run the pre-installed apache1.3 on Mac OS X
10.4.10 and used the --with-apache-hooks option on compiling because I
do not have the apache.h source file (since I haven't compiled apache).

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

[2007-09-03 13:48:09] info at rchu dot nl

I have sort of the same bug I think.

test.php
<?php

function test() { echo 'test'; }

test();

?>

works fine the first time. Then after a reload it gives an cannot
redeclare test() error. Same error after second reload etc. Modify the
file (add a space or something like that) and it runs OK the first time
but after reload same error.

I have compiled PHP 5.2.4 on Darwin Kernel Version 8.10.2.

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/18590

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

Reply via email to