PHP全局变量在函数内部不起作用?

时间:2016-10-11 15:09:02

标签: php arrays global-variables global require

好的,所以我试图研究为什么这不起作用,现在已经超出了我的范围。所以请原谅我。

我有一个名为include.php的PHP文档,其中有2行需要某些文件。

require('/srv/testwebsite.com/public/htdocs/includes/defs.php');
require_once('/srv/differenttestwebsite.com/public/htdocs/includes/functions.php');

然后我在最顶层的另一个PHP脚本上要求这个doc,以便我可以使用在functions.php中创建的函数以及defs.php中的定义和全局数组

require('/srv/crm.testweb.com/public/htdocs/includes/include.php');

defs中的一些数组称为$ acpDropdowns,设置为:

$acpDropdowns['abc'] = array('some'=>'thing','like'=>'this');
$acpDropdowns['xyz'] = array('this'=>'that','etc'=>'etc');

在我的函数中,我有一个名为openWizard的函数,其设置如下:

function openWizard($action,$postTo,$id,$user,$update)
{
    global $acpDropdowns;
    ......
}

当我在此函数中使用$ acpDropdown数组时,不会填充任何内容。为了测试这个,我输入了:

echo "<pre>".$acpDropdowns."</pre>";    
function openWizard($action,$postTo,$id,$user,$update)
{
    global $acpDropdowns;
    if(!$acpDropdowns)
    {
        echo "No Dropdowns";
    }
    .....
}

这导致的是当我加载我的页面并且包含了include.php文件时,正如预期的那样是一个完整的$ acpDropdowns数组,然后当我调用我得到的函数时#34;没有下拉&#34;

see

我想我已经尽可能多地给了,我也跑了

if(!$acpDropdowns)
{
    $included = get_included_files();
    echo "<pre>{$included}</pre>";
}

此输出显示defs.php文件实际包含在内!

0 个答案:

没有答案