PHP 5 function redeclared error

This is a discussion on PHP 5 function redeclared error within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am using PHP 5.0.1 with Apache 2 on Win XP (SP2). My index.php file has ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-11-2005
saayan@farfence.com
 
Posts: n/a
Default PHP 5 function redeclared error

Hi,
I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).

My index.php file has require_once contents.php and also for
functions.php.
My contents.php file also has a require_once for functions.php.

When this code is tested on one machine, it works fine. However on
another machine with identical configuration (same PHP 5.0.1, XP+SP2,
Apache 2), an error message appears :
test_timeout function redeclared.
(test_timeout function is in functions.php file.)

We have tested it with PHP 5.0.3 - same problem happens.

For running the PHP, MySQL, Apache combination, our setup steps are:
1. Install PHP - customize the .ini file
2. Install MySQL
3. Install Apache - customize the httpd.conf for using PHP
4. Copy libmysql.dll from ...\php\ dir to windows\system32 dir

The configurations are exactly same for both machines. The two machines
have identical PHP, MySQL and Apache physical directory paths. The
php.ini and httpd.conf (for apache) are copied from machine 1 to
machine 2. And we are testing the code locally using localhost.

Can anyone please give some hint as to the possible cause of this
problem. Am I missing something here?

Thanks,
Saayan

The file locations

home/index.php
home/secure/contents.php
home/secure/functions.php

in index.php:
// blah blah
require_once("secure/contents.php");
// blah blah
require_once("secure/functions.php");

in contents.php:
// blah blah
require_once("functions.php");
// blah blah

Reply With Quote
  #2 (permalink)  
Old 01-12-2005
Andy Hassall
 
Posts: n/a
Default Re: PHP 5 function redeclared error

On 11 Jan 2005 09:01:09 -0800, saayan@farfence.com wrote:

>Hi,
>I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
>
>My index.php file has require_once contents.php and also for
>functions.php.
>My contents.php file also has a require_once for functions.php.
>
>When this code is tested on one machine, it works fine. However on
>another machine with identical configuration (same PHP 5.0.1, XP+SP2,
>Apache 2), an error message appears :
>test_timeout function redeclared.
>(test_timeout function is in functions.php file.)
>
>We have tested it with PHP 5.0.3 - same problem happens.
>
>For running the PHP, MySQL, Apache combination, our setup steps are:
>1. Install PHP - customize the .ini file
>2. Install MySQL
>3. Install Apache - customize the httpd.conf for using PHP
>4. Copy libmysql.dll from ...\php\ dir to windows\system32 dir
>
>The configurations are exactly same for both machines. The two machines
>have identical PHP, MySQL and Apache physical directory paths. The
>php.ini and httpd.conf (for apache) are copied from machine 1 to
>machine 2. And we are testing the code locally using localhost.
>
>Can anyone please give some hint as to the possible cause of this
>problem. Am I missing something here?
>
>Thanks,
>Saayan
>
>The file locations
>
>home/index.php
>home/secure/contents.php
>home/secure/functions.php
>
>in index.php:
>// blah blah
>require_once("secure/contents.php");
>// blah blah
>require_once("secure/functions.php");
>
>in contents.php:
>// blah blah
>require_once("functions.php");
>// blah blah


Nothing looks obviously wrong...

It's Windows so differences in filename case might be an issue? (I can't
reproduce the issue though).

You say the configs are the same - if you hadn't said php.ini is identical I'd
wonder if it's an include_path issue somehow picking up a different
functions.php between the two calls?

Can you demonstrate it failing, e.g. by setting up mini versions of that
directory structure with a dummy function in functions.php, and running it from
the command line? e.g. here's it not failing:

D:\public_html\php_usenet\require_once>type index.php
<?php
print __FILE__ ."\n";
require_once('secure/contents.php');
require_once('secure/functions.php');
?>
D:\public_html\php_usenet\require_once>type secure\contents.php
<?php
print __FILE__ ."\n";
require_once('secure/functions.php');
?>
D:\public_html\php_usenet\require_once>type secure\functions.php
<?php
print __FILE__ ."\n";
function x()
{
print "x";
}
?>
D:\public_html\php_usenet\require_once>d:\php-5.0.3-Win32\php.exe -q index.php
D:\public_html\php_usenet\require_once\index.php
D:\public_html\php_usenet\require_once\secure\cont ents.php
D:\public_html\php_usenet\require_once\secure\func tions.php

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #3 (permalink)  
Old 01-12-2005
Chung Leong
 
Posts: n/a
Default Re: PHP 5 function redeclared error

<saayan@farfence.com> wrote in message
news:1105462869.199797.327200@z14g2000cwz.googlegr oups.com...
> Hi,
> I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
>
> My index.php file has require_once contents.php and also for
> functions.php.
> My contents.php file also has a require_once for functions.php.
>
> When this code is tested on one machine, it works fine. However on
> another machine with identical configuration (same PHP 5.0.1, XP+SP2,
> Apache 2), an error message appears :
> test_timeout function redeclared.
> (test_timeout function is in functions.php file.)
>
> We have tested it with PHP 5.0.3 - same problem happens.
>
> For running the PHP, MySQL, Apache combination, our setup steps are:
> 1. Install PHP - customize the .ini file
> 2. Install MySQL
> 3. Install Apache - customize the httpd.conf for using PHP
> 4. Copy libmysql.dll from ...\php\ dir to windows\system32 dir
>
> The configurations are exactly same for both machines. The two machines
> have identical PHP, MySQL and Apache physical directory paths. The
> php.ini and httpd.conf (for apache) are copied from machine 1 to
> machine 2. And we are testing the code locally using localhost.
>
> Can anyone please give some hint as to the possible cause of this
> problem. Am I missing something here?
>
> Thanks,
> Saayan
>
> The file locations
>
> home/index.php
> home/secure/contents.php
> home/secure/functions.php
>
> in index.php:
> // blah blah
> require_once("secure/contents.php");
> // blah blah
> require_once("secure/functions.php");
>
> in contents.php:
> // blah blah
> require_once("functions.php");
> // blah blah


Your require_once statements are kinda screwy. contents.php is actually
loading the home/functions.php, because relative paths are relative to the
running script (home/index.php) and not the file which contains the
include/require statement.


Reply With Quote
  #4 (permalink)  
Old 01-12-2005
Andy Hassall
 
Posts: n/a
Default Re: PHP 5 function redeclared error

On Tue, 11 Jan 2005 18:37:17 -0500, "Chung Leong" <chernyshevsky@hotmail.com>
wrote:

>> home/index.php
>> home/secure/contents.php
>> home/secure/functions.php
>>
>> in index.php:
>> // blah blah
>> require_once("secure/contents.php");
>> // blah blah
>> require_once("secure/functions.php");
>>
>> in contents.php:
>> // blah blah
>> require_once("functions.php");
>> // blah blah

>
>Your require_once statements are kinda screwy. contents.php is actually
>loading the home/functions.php, because relative paths are relative to the
>running script (home/index.php) and not the file which contains the
>include/require statement.


http://uk2.php.net/manual/en/function.include.php

" Files for including are first looked in include_path relative to the current
working directory and then in include_path relative to the directory of current
script. E.g. if your include_path is ., current working directory is /www/, you
included include/a.php and there is include "b.php" in that file, b.php is
first looked in /www/ and then in /www/include/. If filename begins with ../,
it is looked only in include_path relative to the current working directory."

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #5 (permalink)  
Old 01-12-2005
saayan@farfence.com
 
Posts: n/a
Default Re: PHP 5 function redeclared error

Thanks for your reply. There is no home/functions.php file. There is
only one functions.php file and it is home/secure/functions.php.
Obviously the script has no problem locating the file for loading. The
multiple loading is the issue here.

The only difference between the two require statements is:
index.php says -> require_once("secure/functions.php");
contents.php says -> require once ("functions.php");
So, even though they are the same file, is the require_once getting
confused by the parameters passed in and trying to load the same file
twice?

What is perplexing -> how is it working well on one machine and not
working on another with exactly the same php.ini file.

Andy, thanks for your tips. I shall try to simulate the problem with
simple scripts as you said.
Cheers,
Saayan

Chung Leong wrote:
> <saayan@farfence.com> wrote in message
> news:1105462869.199797.327200@z14g2000cwz.googlegr oups.com...
> > Hi,
> > I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
> >
> > My index.php file has require_once contents.php and also for
> > functions.php.
> > My contents.php file also has a require_once for functions.php.
> >
> > When this code is tested on one machine, it works fine. However on
> > another machine with identical configuration (same PHP 5.0.1,

XP+SP2,
> > Apache 2), an error message appears :
> > test_timeout function redeclared.
> > (test_timeout function is in functions.php file.)
> >
> > We have tested it with PHP 5.0.3 - same problem happens.
> >
> > For running the PHP, MySQL, Apache combination, our setup steps

are:
> > 1. Install PHP - customize the .ini file
> > 2. Install MySQL
> > 3. Install Apache - customize the httpd.conf for using PHP
> > 4. Copy libmysql.dll from ...\php\ dir to windows\system32 dir
> >
> > The configurations are exactly same for both machines. The two

machines
> > have identical PHP, MySQL and Apache physical directory paths. The
> > php.ini and httpd.conf (for apache) are copied from machine 1 to
> > machine 2. And we are testing the code locally using localhost.
> >
> > Can anyone please give some hint as to the possible cause of this
> > problem. Am I missing something here?
> >
> > Thanks,
> > Saayan
> >
> > The file locations
> >
> > home/index.php
> > home/secure/contents.php
> > home/secure/functions.php
> >
> > in index.php:
> > // blah blah
> > require_once("secure/contents.php");
> > // blah blah
> > require_once("secure/functions.php");
> >
> > in contents.php:
> > // blah blah
> > require_once("functions.php");
> > // blah blah

>
> Your require_once statements are kinda screwy. contents.php is

actually
> loading the home/functions.php, because relative paths are relative

to the
> running script (home/index.php) and not the file which contains the
> include/require statement.


Reply With Quote
  #6 (permalink)  
Old 01-12-2005
Michael Fesser
 
Posts: n/a
Default Re: PHP 5 function redeclared error

.oO(Chung Leong)

><saayan@farfence.com> wrote in message
>news:1105462869.199797.327200@z14g2000cwz.googleg roups.com...
>
>> in index.php:
>> // blah blah
>> require_once("secure/contents.php");
>> // blah blah
>> require_once("secure/functions.php");
>>
>> in contents.php:
>> // blah blah
>> require_once("functions.php");
>> // blah blah

>
>Your require_once statements are kinda screwy. contents.php is actually
>loading the home/functions.php


Nope. contents.php and functions.php are stored in the same directory,
so the following

require_once("functions.php");

works as expected. But I would write it as

require_once 'functions.php';

>because relative paths are relative to the
>running script (home/index.php) and not the file which contains the
>include/require statement.


It makes a difference if the path in the include/require statement
starts with "../" or not.

Micha
Reply With Quote
  #7 (permalink)  
Old 01-12-2005
saayan@farfence.com
 
Posts: n/a
Default Re: PHP 5 function redeclared error

Thanks. But other than the syntax, what is the semantic difference
between
require_once("functions.php");

and

require_once 'functions.php';

Reply With Quote
  #8 (permalink)  
Old 01-12-2005
Versine
 
Posts: n/a
Default Re: PHP 5 function redeclared error

Issue is solved. Thanks a lot for all your replies.

There is nothing wrong with PHP w.r.t require_once. The problem is,
in machine 2:
..../home -> has a functions.php
..../home/secure/ -> also has a functions.php

machine 1:
has only one functions.php. In .../home/secure/

It is a source control issue.
Last month, the .php files were moved to /home/secure directory, but
the person moving the files forgot to delete the old files from /home
dir of the CVS server. So, in machine 2, when we synced with the CVS
server, - two copies of functions.php were checked out to the source
tree.

And I am suitably ashamed for not cross-checking the version control
before posting.

Reply With Quote
  #9 (permalink)  
Old 01-12-2005
sesser@gmail.com
 
Posts: n/a
Default Re: PHP 5 function redeclared error

>There is nothing wrong with PHP w.r.t require_once. The problem is, in
machine 2:
>.../home -> has a functions.php
>.../home/secure/ -> also has a functions.php


this proves that the require_once('functions.php') in contents.php is
failing on server 1... there is no functions.php in the 'home'
directory (which is where PHP is looking for the file).

Reply With Quote
  #10 (permalink)  
Old 01-12-2005
Michael Fesser
 
Posts: n/a
Default Re: PHP 5 function redeclared error

.oO(saayan@farfence.com)

>Thanks. But other than the syntax, what is the semantic difference
>between
>require_once("functions.php");
>
>and
>
>require_once 'functions.php';


Nothing, except that a double quoted string forces the interpreter to
look for variables inside, while a single quoted string is used as-is.

The parentheses can be omitted because include/require are language
constructs, not functions (like echo/print for example). But that's
rather cosmetical or "personal preference", it makes no difference in
code execution.

Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:48 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0