PHP 对同一文件中的重新声明进行投诉,但仅在声明时进行投诉。漏洞?
我收到以下错误消息:
[Wed Sep 21 21:19:46 2011] [error] [client 127.0.0.1] PHP Fatal error: Cannot redeclare db_get_groups()
(previously declared in /Library/WebServer/Documents/SMICAdmin/databasescripts/db_get_groups.php:4)
in /Library/WebServer/Documents/SMICAdmin/databasescripts/db_get_groups.php on line 24,
referer: http://localhost/SMICAdmin/index.php
如您所见,错误消息抱怨同一脚本中的同一函数 db_get_groups() 两次。但事实并非如此,整个文件都包含在此处(db_get_groups.php):
<?php
function db_get_groups($dbconnection){ //Line 4
$query = "SELECT id FROM groups";
$result = mysqli_query($dbconnection, $query);
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$grouplist = Array();
foreach ($rows as $key => $value) {
error_log(" Value -> ".$value['id']);
$grouplist[] = $value['id'];
}
return $grouplist;
} //Line 24
?>
在整个项目中搜索“db_get_groups”时,我只能找到下面唯一的声明,并且该文件包含在其他两个文件中以供使用。
我确实尝试查找是否以某种方式多次导入文件,但找不到任何内容。
有什么问题以及如何解决它?感觉这个真的很接地气……
I am getting following error message:
[Wed Sep 21 21:19:46 2011] [error] [client 127.0.0.1] PHP Fatal error: Cannot redeclare db_get_groups()
(previously declared in /Library/WebServer/Documents/SMICAdmin/databasescripts/db_get_groups.php:4)
in /Library/WebServer/Documents/SMICAdmin/databasescripts/db_get_groups.php on line 24,
referer: http://localhost/SMICAdmin/index.php
As you can see, the error message complains that the same function, db_get_groups(), twice in the same script. But it's not, the entire file is included here (db_get_groups.php):
<?php
function db_get_groups($dbconnection){ //Line 4
$query = "SELECT id FROM groups";
$result = mysqli_query($dbconnection, $query);
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$grouplist = Array();
foreach ($rows as $key => $value) {
error_log(" Value -> ".$value['id']);
$grouplist[] = $value['id'];
}
return $grouplist;
} //Line 24
?>
When doing a search for "db_get_groups" in the entire project I can only find the only declaration below and the file is inluded in two other files for usage.
I did try to find if I done some import of the file more than once in some way, couldn't find any.
What's the problem and how do I fix it? Feels really wired this one...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最重要的是,您看到错误消息的唯一方法是该函数被定义了两次。有两种常见的方式可能会发生这种情况。您应该仔细检查这两个内容:
db_get_groups
。db_get_groups.php
被多次包含。考虑使用include_once
/require_once
而不仅仅是include
/require
。The bottom line is that the only way you would ever see that error message is if the function is defined twice. There's two common ways this could happen. You should double check both of these:
db_get_groups
.db_get_groups.php
is included multiple times. Consider usinginclude_once
/require_once
instead of justinclude
/require
.使用:
require_once(“db_get_groups.php”);
或者,
include_once(“db_get_groups.php”);
而不仅仅是要求或包含。
Use:
require_once("db_get_groups.php");
Or,
include_once("db_get_groups.php");
Instead of just require or include.
尝试删除该定义,然后调用 db_get_groups(),查看错误日志中是否有任何提示。
如果这不起作用,您是否可能多次包含该文件?您是否将包含它的其他文件都包含在某处?
您使用了 require/include 还是 require_once/include_once ?尝试*_一次。
该文件有符号链接吗?如果是这样,你能把他们也包括在内吗?
最后,如果您在函数外部(之前)添加 log() 或 echo() ,它会对您有所帮助。
Try removing that definition, and calling db_get_groups(), see if there are any hints in the error logs.
If that doesn't go anywhere, are you perhaps including the file more than one time? Are you including both those other files that include it somewhere?
Did you use require/include or require_once/include_once? Try *_once.
Are there any symbolic links to that file? If so, could you be including them as well?
Finally, it could help you if you added a log() or echo() outside the function (before it).