By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

PHP 5 function redeclared error

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
On 11 Jan 2005 09:01:09 -0800, sa****@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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
<sa****@farfence.com> wrote in message
news:11**********************@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.
Jul 17 '05 #3

P: n/a
On Tue, 11 Jan 2005 18:37:17 -0500, "Chung Leong" <ch***********@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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4

P: n/a
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:
<sa****@farfence.com> wrote in message
news:11**********************@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.


Jul 17 '05 #5

P: n/a
.oO(Chung Leong)
<sa****@farfence.com> wrote in message
news:11**********************@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
Jul 17 '05 #6

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

and

require_once 'functions.php';

Jul 17 '05 #7

P: n/a
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.

Jul 17 '05 #8

P: n/a
>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).

Jul 17 '05 #9

P: n/a
.oO(sa****@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
Jul 17 '05 #10

P: n/a
.oO(se****@gmail.com)
There is nothing wrong with PHP w.r.t require_once. The problem is, inmachine 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...


No!
there is no functions.php in the 'home'
directory (which is where PHP is looking for the file).


PHP looks there first, if it can't find one it looks in /home/secure
(the same directory where contents.php is stored). It's all correct.

Micha
Jul 17 '05 #11

P: n/a
My bad. I was unaware that it would look in the 'secure' directory if
it failed in the 'home' directory. Not to mention that 'require()'
would produce a fatal error if it couldn't find a file.

thanks
r.

Jul 17 '05 #12

P: n/a
I was trying to simplify things a bit. Unless you change it with a call
to chdir(), the cwd is the same as the script directory. Including a
file in a different directory does not change the cwd to that
directory.

I'm at a loss as to why require_once("functions.php") manages to find
secure/functions.php. I think most of us would agree that it's not
supposed to happen, unless /home/secure is in the include_path. If it
is, then why does require_once() fail to see that it's the same file?
Since this happens on Windows, maybe it's a forward slash vs. backward
slash misinterpretation within PHP.

In any event, providing absolute paths to include/require is the
preferred practice. That way you know for certain what you're
including. An example:

define('SECURE_INCLUDE_ROOT', dirname(__FILE__) . "/secure/");

function require_secure($filename) {
require_once(SECURE_INCLUDE_ROOT . $filename);
}

Jul 17 '05 #13

P: n/a
On 12 Jan 2005 12:59:47 -0800, "ch***********@hotmail.com"
<ch***********@hotmail.com> wrote:
I was trying to simplify things a bit. Unless you change it with a call
to chdir(), the cwd is the same as the script directory. Including a
file in a different directory does not change the cwd to that
directory.


Yes, that's the point from the manual snippet I posted. cwd is searched first,
then the directory containing the current script. When you include a script
outside the cwd, then all include_path directories relative the directory
containing the included script become candidates for searching, once all
equivalents relative to cwd fail.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #14

P: n/a
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:fa********************************@4ax.com...
On 12 Jan 2005 12:59:47 -0800, "ch***********@hotmail.com"
<ch***********@hotmail.com> wrote:
I was trying to simplify things a bit. Unless you change it with a call
to chdir(), the cwd is the same as the script directory. Including a
file in a different directory does not change the cwd to that
directory.
Yes, that's the point from the manual snippet I posted. cwd is searched

first, then the directory containing the current script. When you include a script outside the cwd, then all include_path directories relative the directory
containing the included script become candidates for searching, once all
equivalents relative to cwd fail.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool


Crap. I got egg on my face. I've always understood "current script" as being
the file reported by PHP_SELF. Turned out I'm way off. Thank you, Andy and
Michael, for point it out.
Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.