php - 另一个文件中的 PHP 超全局变量
问题描述
我想在文件 file_one 中声明一个变量(php 代码)并在 file_two 中使用它。
根据其文档,可以从任何地方访问超级博客。但在我的情况下可能不是?我在第一个文件中声明了 $a 但我无法在第二个文件中使用它。虽然我可以在第一个文件中的函数中使用它。
$GLOBALS['a']= 3;
function test() {
echo $GLOBALS['a'];
}
test();
这按预期工作。但:
文件一:
$GLOBALS['a']= 3;
文件二:
echo $GLOBALS['a'];
导致通知:未定义索引:a
Include 'file_one.php" 不是我想使用的东西,因为 file_one 做了很多事情。
解决方案
Store the value of global in a session variable. It will work. Or you can define it in your head/header/function or in any common file.
推荐阅读
- java - 安装摄取附件插件错误
- javascript - 将对象数组转换为字符串 es6
- java - 无权拨打汇率服务
- javascript - 鼠标悬停不适用于第一个悬停角度 5
- php - css 文件未加载并显示 301 Moved Permanently(来自磁盘缓存)
- ctags - 需要帮助从 c 标头中提取函数信息
- mysql - 如何按mysql中的特定值对结果进行排序
- javascript - 根据 c# 中的用户/数据库输入从资源文件中加载值
- android - 如何使用数据绑定在relativelayout中设置layout_centerVertical
- excel - 如何在excel中获取日期是否是一个月的第一个,第二个等星期一