包含文件中的 PHP $GLOBALS 变量问题
我最近将一个大型 CubeCart 安装移至新服务器,它产生了一大堆问题。其中大多数我都被错误地解决了,但我被困在这一点上:
在主index.php文件中包含配置文件,它设置像$glob['rootDir']这样的关键变量。然后几行之后,在主 index.php 文件中包含另一个重要脚本,并调用其中一些 $glob 变量,但在 $GLOBALS 超全局下。但这不起作用。如果我放第二个包含文件 var_dump($GLOBALS) 它就在那里......但是如果我放 echo $GLOBALS['rootDir'] 我什么也得不到。 我没有收到任何严重错误或任何东西,只是未定义索引。
这是 PHP 设置的问题吗?该网站之前在以前的服务器上运行良好,但我不知道它运行的 PHP 版本或具体设置。
代码示例:
主索引文件:
//INCLUDE CORE VARIABLES & FUNCTIONS
include_once("includes/global.inc.php");
//... other stuff ...
include_once("includes/sessionStart.inc.php");
GLOBAL.INC.PHP:
$glob['dbhost'] = 'localhost';
//other variables, including $glob['rootRel'];
SESSIONSTART.INC.PHP:
$sessionDomain = substr($GLOBALS['rootRel'],0, strlen($GLOBALS['rootRel'])-1);
//the above is where it throws Undefined Index
谢谢!
I recently moved a large CubeCart installation to a new server and it created a whole bunch of issues. Most of them I'm getting sorted out error by error, but I'm stuck on this one:
In the main index.php file the config file is included, which sets key variables like $glob['rootDir']. Then a few lines later in the main index.php file another important script is included and calls some of those $glob variables, but under the $GLOBALS superglobal. However this isn't working. If I put on the second included file var_dump($GLOBALS) it's all there... but if I put echo $GLOBALS['rootDir'] I get nothing.
I'm not getting any bad errors or anything, just Undefined Index.
Is this an issue with PHP settings? The site was working fine before on the previous server, though I don't know what version of PHP it was running or specific settings.
Code samples:
MAIN INDEX FILE:
//INCLUDE CORE VARIABLES & FUNCTIONS
include_once("includes/global.inc.php");
//... other stuff ...
include_once("includes/sessionStart.inc.php");
GLOBAL.INC.PHP:
$glob['dbhost'] = 'localhost';
//other variables, including $glob['rootRel'];
SESSIONSTART.INC.PHP:
$sessionDomain = substr($GLOBALS['rootRel'],0, strlen($GLOBALS['rootRel'])-1);
//the above is where it throws Undefined Index
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$glob 和 $GLOBALS 是不同的变量,因此这种行为是可以的。
$glob and $GLOBALS are different variables, so this behaviour is ok.