开发者

PHP global variable problem accross multiple files

开发者 https://www.devze.com 2023-03-30 08:59 出处:网络
so I have site structure like this. I have index.php, that includes() include.php, which includes functions.php and a bunch of other files.

so I have site structure like this. I have index.php, that includes() include.php, which includes functions.php and a bunch of other files. What I want to do is write $GLOBALS["something"] = 'something here'; in functions.php and after do echo $something; in index.php so it would print something here, but for som开发者_开发知识库e reason it returns nothing. Where is my mistake?


In index.php you either have to say echo $GLOBALS['something'] or global $something; echo $something; in order to register $something as a global variable.

However, I would discourage using global variables at all and instead use constants if you have to.

0

精彩评论

暂无评论...
验证码 换一张
取 消