问题描述
我在Win XP(SP2)上使用PHP 5.0.1和Apache 2.
我的index.php文件有require_once内容.php以及
functions.php。
我的contents.php文件还有一个require_once for functions.php。
在一台机器上测试此代码时,它可以正常工作。但是在
另一台具有相同配置的机器上(相同的PHP 5.0.1,XP + SP2,
Apache 2),会出现一条错误消息:
test_timeout函数重新声明。
(test_timeout函数在functions.php文件中。)
我们用PHP 5.0.3测试了它 - 同样的问题发生了。
为了运行PHP,MySQL,Apache组合,我们的设置步骤是:
1.安装PHP - 自定义.ini文件
2.安装MySQL
3.安装Apache - 自定义httpd.conf以使用PHP
4.从... \ php \\复制libmysql.dll \\ dir to windows \ system32 dir
两台机器的配置完全相同。两台机器
具有相同的PHP,MySQL和Apache物理目录路径。
php.ini和httpd.conf(用于apache)从机器1复制到
机器2.我们正在使用localhost在本地测试代码。
任何人都可以提供一些关于这个问题的可能原因的暗示。我在这里错过了什么吗?
谢谢,
Saayan
文件位置
home / index.php
home / secure / contents.php
home / secure / functions.php
$ index.php中的b $ b:
// 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
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
推荐答案
没什么看似明显错的......
这是Windows,因此文件名中的差异可能是一个问题? (我不能
重现这个问题)。
你说配置是一样的 - 如果你没有说php.ini相同的我会
想知道这两个电话之间是否存在一个包含路径问题以某种方式获取不同的
functions.php?
你能否证明它失败了,例如通过在functions.php中使用虚函数设置那个
目录结构的迷你版本,并从命令行运行它?
命令行?例如这里没有失败:
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>输入secure\contents.php
<?php
print __FILE __。" \ n" ;;
require_once(''secure / functions.php'');
?>
D:\public_html \ php_usenet \require_once>输入secure\functions.php
<?php
print __FILE __。" \ n" ;;
函数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 \ quire_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>空间:磁盘使用情况分析工具
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
你的require_once语句有点棘手。 contents.php实际上是加载home / functions.php的
,因为相对路径是相对于
运行脚本(home / index.php)而不是文件包含
include / require语句。
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.
你的require_once语句有点棘手。 contents.php实际上是加载home / functions.php,因为相对路径是相对于运行脚本(home / index.php)而不是包含
include /的文件需要声明。
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.
"包含的文件首先在相对于当前
工作目录的include_path中查找,然后在相对于当前
脚本目录的include_path中查找。例如。如果你的include_path是。,当前的工作目录是/ www /,你包括/ b.php包括b.php在该文件中,b.php是/ b $ b首先在/ www /然后在/ www / include /中查找。如果文件名以../开头,
它只在相对于当前工作目录的include_path中查找。
-
Andy Hassall /< an ** @ andyh.co.uk> /< http://www.andyh.co.uk>
< http://www.andyhsoftware.co.uk/space>空间:磁盘使用情况分析工具
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
这篇关于PHP 5函数重新声明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!