跨文件的PHP全局变量 [英] PHP global variables across files
本文介绍了跨文件的PHP全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,也许我的大脑刚刚关闭,但是我无法使它正常工作.
Ok, maybe my brain is just shut off, but I can't get this to work.
这是完整的代码:
Page1.php:
Page1.php:
<?php
$something = "hello";
include "Page2.php";
?>
Page2.php:
Page2.php:
<?php
echo $something;
?>
所需的输出(导航到Page1.php时):
Desired output (when navigating to Page1.php):
hello
实际输出为空白.我尝试将global关键字放在任何地方,但没有任何反应.我想念什么吗?
The real output is blank. I have tried putting the global keyword everywhere, and nothing happens. Am I missing something?
推荐答案
我无法复制此错误,只能在本地主机上尝试此错误,然后从此处复制并粘贴您的代码.我怀疑您存在某种语法错误.
I cannot replicate this error, just tried this on my localhost and copied and pasted your code from here. I suspect you have some sort of syntax error.
打开错误报告,看看是否有任何错误.
Turn on error reports and see if you get any errors.
这篇关于跨文件的PHP全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文