Php ob_end_包含后未清除缓冲区
我使用此代码在我的CMS中获取模块信息:Php ob_end_包含后未清除缓冲区,php,include,hook,redeclare,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 $hoo
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';
}
这段代码在PHP5.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
如何解决这个问题?这是一个糟糕的体系结构。我不明白它在上一个版本中是如何工作的。如果每个模块都有函数
modname
和modver
,那么它的错误肯定是存在的,因为在php中,不能用相同的名称声明多个函数。在您的例子中,我认为您首先包括文件\modules\example\config.php
,然后是\modules\Z48ilWd2l80cYed8\config.php
。请检查并删除include\modules\example\config.php
您可能在某个地方得到了一个include()
或require()
而不是include\u once()
/require\u once()
,导致config.php被加载两次。我使用此代码ob\u start();包括一次(mydir);ob_end_clean()for在缓冲区中加载每个config.php,然后清除缓冲区以防止重新声明函数,但它不起作用now@lord_viper你找不到include\modules\example\config.php
?我找到了这个,include很完美,但是ob\u end\u clean不起作用,清除缓冲区这个代码对我的cms小工具很有效