Treat
Treat

Reputation: 192

PHP global variable problem accross multiple 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 some reason it returns nothing. Where is my mistake?

Upvotes: 2

Views: 3608

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191729

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.

Upvotes: 3

Related Questions