包含文件中的 PHP $GLOBALS 变量问题

发布于 2024-11-16 16:11:08 字数 902 浏览 3 评论 0原文

我最近将一个大型 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Spring初心 2024-11-23 16:11:08

$glob 和 $GLOBALS 是不同的变量,因此这种行为是可以的。

$glob and $GLOBALS are different variables, so this behaviour is ok.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文