这可能是一个愚蠢的问题,但我被困在这个愚蠢的问题部分2小时。
我有这个功能,它检查一个特定的配置文件的变量是不是空的。 这里的功能: -
include 'inc.config.php';
function not_valid_settings()
{
if((empty($_GLOBAL['id'])) || (empty($_GLOBAL['username'])) || empty($_GLOBAL['password']))
{
return true;
}
else
{
return false;
}
}
这里的配置inc.config.php文件:
$_GLOBAL=array();
$_GLOBAL['id'] = "asas";
$_GLOBAL['username'] = "asas";
$_GLOBAL['password'] = 'as';
函数调用
include 'inc/inc.functions.php';
if(not_valid_settings())
{
echo "Please enter correct entries in inc/inc.config.php";
exit();
}
出于某种原因,我总是得到请输入正确的细节。即使我的$_GLOBAL['username']='';
。 我在这里做什么错?
我不认为'$ _GLOBAL'做你认为它做的,你是否可能意思是'$ GLOBALS'? (但是你真的不应该使用) – cdhowie 2014-09-01 20:26:48
是的,我实际上使用'$ _GLOBAL'作为所有全局设置变量的变量。 – user2619381 2014-09-01 20:27:36
FWIW:在暴露helper函数的文件中不要包含“config”(它应该在调用上下文中由全局mangling设置) – user2864740 2014-09-01 20:28:36