ob_end_clean包含后不清除缓冲区

时间:2013-10-29 15:21:31

标签: php include hook redeclare

我正在使用此代码在CMS中获取模块信息:

global $hook;
$hook = new bn_hookfunc;

ob_start();
include_once($mydir);
ob_end_clean();
$mod_name = $hook->call_function('module_name');
$mod_ver  = $hook->call_function('module_version');

我的模块config.php看起来像这样:

global $hook;
$hook->module_name='modname';
$hook->module_version='modver';

function modname()
{
    return 'test module';
}

function modver()
{
    return 'v1.0.0';
}

此代码在PHP 5.4中完美运行。

但我将xampp更新为1.83,因此PHP更新为5.5.3,现在我有这个错误:

Cannot redeclare modname() (previously declared in \modules\example\config.php:13) in \modules\Z48ilWd2l80cYed8\config.php on line 14

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是一个糟糕的架构。我不明白它在上一版本中是如何工作的。如果每个模块都有函数modnamemodver它必须有错误,因为在php中你不能声明几个具有相同名称的函数。在您的情况下,我认为您首先包含文件\modules\example\config.php而不是\modules\Z48ilWd2l80cYed8\config.php。请检查并删除\modules\example\config.php