fatal error: cannot redeclare [message #171902] |
Thu, 20 January 2011 17:38 |
Jivanmukta
Messages: 20 Registered: January 2011
Karma: 0
|
Junior Member |
|
|
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():
<?php
require_once 'common.inc.php';
if (!isset($db)) {
$db = null;
}
$inTransaction = false;
$regions = array();
$estateTypes = array();
$ownership = array();
$standards = array();
$furnitureTypes = array();
$offerTypes = array();
$currencies = array();
$agencies = array();
$priceFor = array();
$units = array('M2' => 'm<sup>2<\/sup>', 'HA' => 'ha (hektarów)');
$vulgar = array();
function openDatabase() {
global $db;
try {
$db = new PDO('mysql:host=' . MYSQL_SERVER . ';dbname=' .
MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD);
$db->exec('SET NAMES latin2');
$db->exec('SET CHARACTER SET latin2 COLLATE latin2_general_ci');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
register_shutdown_function('closeDatabase');
} catch (PDOException $e) {
return false;
}
return true;
}
Remaining required_once files do not contain function openDatabase().
|
|
|
Re: fatal error: cannot redeclare [message #171903 is a reply to message #171902] |
Thu, 20 January 2011 18:14 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: fatal error: cannot redeclare [message #171905 is a reply to message #171903] |
Thu, 20 January 2011 18:59 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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?
--
Shelly
|
|
|
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: 0
|
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
--
|
|
|
Re: fatal error: cannot redeclare [message #171918 is a reply to message #171903] |
Fri, 21 January 2011 13:38 |
Jivanmukta
Messages: 20 Registered: January 2011
Karma: 0
|
Junior Member |
|
|
> Either you've got another definition of openDatabase() somewhere and
> don't realize it,
robert@pecet:~/public_html$ find . -exec grep -H -n 'function
openDatabase' {} \;
../include/database.inc.php:25:function openDatabase() {
> or you are including (or requiring) database.inc.php
> in one of your include files, probably without _once.
No, I don't.
|
|
|
Re: fatal error: cannot redeclare [message #171921 is a reply to message #171918] |
Fri, 21 January 2011 14:50 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 1/21/2011 8:38 AM, Jivanmukta wrote:
>> Either you've got another definition of openDatabase() somewhere and
>> don't realize it,
>
> robert@pecet:~/public_html$ find . -exec grep -H -n 'function
> openDatabase' {} \;
> ./include/database.inc.php:25:function openDatabase() {
>
>> or you are including (or requiring) database.inc.php
>> in one of your include files, probably without _once.
>
> No, I don't.
The problem is somewhere in your code. The interpreter doesn't just put
out this message for no reason.
Most often this is caused by an include you forgot about. Other options
are files automatically included in the php.ini file, i.e. by the
auto_prepend_file directive, an include path which is not what you
expect, thereby including a different file than you expect, etc.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: fatal error: cannot redeclare [message #171922 is a reply to message #171921] |
Fri, 21 January 2011 15:12 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 1/21/2011 3:50 PM, Jerry Stuckle wrote:
> On 1/21/2011 8:38 AM, Jivanmukta wrote:
>>> Either you've got another definition of openDatabase() somewhere and
>>> don't realize it,
>>
>> robert@pecet:~/public_html$ find . -exec grep -H -n 'function
>> openDatabase' {} \;
>> ./include/database.inc.php:25:function openDatabase() {
>>
>>> or you are including (or requiring) database.inc.php
>>> in one of your include files, probably without _once.
>>
>> No, I don't.
>
> The problem is somewhere in your code. The interpreter doesn't just put
> out this message for no reason.
>
> Most often this is caused by an include you forgot about. Other options
> are files automatically included in the php.ini file, i.e. by the
> auto_prepend_file directive, an include path which is not what you
> expect, thereby including a different file than you expect, etc.
>
Building on Jerry's train of thought: Maybe you use some class that gets
autoloaded, and the include is done inside that class in some method?
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
|
|
|