473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

Jul 17 '05 #1
14 2710
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
<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
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
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
.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
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
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
>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
.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
.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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: chunmok | last post by:
When compile using g++, following error messages appears. /usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared as differe nt kind of symbol /usr/include/sys/systeminfo.h:77:...
11
by: John Collyer | last post by:
Hi, In assembly language you can use a lookup table to call functions. 1. Lookup function address in table 2. Call the function Like: CALL FUNCTION
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
16
by: Rob Somers | last post by:
Say I have the following code: void foo(int some_int); ..... int x = 5; foo(x); ..... void foo(int some_int) {
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
2
by: Jake Barnes | last post by:
In the function below, the reset() method has no effect. What is the correct way to ensure that singletonArrayToHoldElementsForTheNextRenderingOfTheCommunicationBox is empty? function...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
by: newbie | last post by:
Need a virtual function be redeclared in child class? I thought it's not necessary, but g++ compiler complains that I didn't declare foo() in B_Foo. I thought I can optionally do it because...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.