Re: fatal error: cannot redeclare [message #171917 is a reply to message #171905] |
Fri, 21 January 2011 08:19 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 20/01/2011 19:59, sheldonlg escribió/wrote:
> On 1/20/2011 1:14 PM, Jerry Stuckle wrote:
>> On 1/20/2011 12:38 PM, Jivanmukta wrote:
>>> Hello,
>>> I have fatal error "Cannot redeclare openDatabase()". My script starts
>>> with:
>>>
>>> <?php
>>> require_once 'include/common.inc.php';
>>> require_once 'include/functions.inc.php';
>>> require_once 'include/database.inc.php';
>>> require_once 'include/announcement.inc.php';
>>> require_once 'include/Captcha.php';
>>> if ($_SERVER['REQUEST_METHOD'] != 'POST') {
>>> error(ERRMSG_POST_ALLOWED_ONLY);
>>> }
>>> sessionBegin();
>>> savePostInSession();
>>> if (!openDatabase()) {
>>> error(ERRMSG_DATABASE_ACCESS_PROBLEM);
>>> }
>>>
>>> where database.inc.php contains single definition of openDatabase():
>>>
>> <rest of code snipped>
>>
>> Either you've got another definition of openDatabase() somewhere and
>> don't realize it, or you are including (or requiring) database.inc.php
>> in one of your include files, probably without _once.
>>
>
> I never thought about this before, butnow that it came up, would it make
> a difference if the database.inc.php was included in another included
> file before this line
>
> "require_once 'include/database.inc.php';"
>
> or after (without a _once_). I would think that if it were included
> first without a _once, then this current line would not be included
> because it has a _once. If it occurs after this line, then it would be
> doubly included because this line would be the first to include it.
>
> If what I say is correct, then I would look in the code after this line.
>
> What say you guys about my question?
We say that it's astonishing simple to test:
inc.txt
=======
Hello, World!
test.php
========
include 'inc.txt';
include_once 'inc.txt';
Run 'test.php' and count the number of hello worlds.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|