在PHP中,从外部调用的文件中获取参数

在PHP中,从外部调用的文件中获取参数,php,file,arguments,Php,File,Arguments,我得到了一个调用模板文件的函数,需要检查文件中指定的参数: 注:此处仅提供缩短的示例 在config.php内部(在类中)-编辑:这应该检查$echo是否为true,以及它是否在模板中设置 // Edit: function check_cb() { // The {$echo} is meant to be from inside the template if ( $echo === TRUE AND $inside_template === TRUE ) r

我得到了一个调用模板文件的函数,需要检查文件中指定的参数:

注:此处仅提供缩短的示例

在config.php内部(在类中)-编辑:这应该检查
$echo
是否为
true
,以及它是否在模板中设置

// Edit:
function check_cb()
{
    // The {$echo} is meant to be from inside the template
    if ( $echo === TRUE AND $inside_template === TRUE )
        return $whatever = 'Using {$echo} in a callback & from inside template is not allowed.'

    return $whatever = 'Check: ok';
}
在template.php内部(在
check\u cb
之前调用)

在另一个类的内部

问题:如何从文件中获取参数?有可能吗?
添加:我也可以修改
示例函数()
,但目前我没有任何好主意。

只需添加此
包含一次(“template.php”)
config.php
文件的开头。 还添加
global$echo
中检查\u cb()
函数

大概是这样的:

include_once("template.php");
function check_cb()
{
    global $echo;
    // The {$echo} is meant to be from inside the template
    if ( $echo === false )
        return $whatever = 'no'

    return $whatever = 'yes';
}
include_once(“template.php”)
将基本上使所有函数、变量从
template.php
config.php
可见。但要在函数外部使用变量定义,必须使用
global
keywor


有关
global
的更多信息,请查看
include\u once
语句。

您是说我应该在每个模板中将echo设置为global?顺便说一句:我更新了Q以使其更清晰(第一个函数+解释)。哦,对不起:我写Q的方式很容易理解错误,而且信息太少-通过编辑修复。
include_once("template.php");
function check_cb()
{
    global $echo;
    // The {$echo} is meant to be from inside the template
    if ( $echo === false )
        return $whatever = 'no'

    return $whatever = 'yes';
}