Is there really such a thing as globals in PHP? I have looked into the online documentaion and I tried to declare a global variable.
I have a web site which uses PHP to create a WordPress blog. On the index.php file I declared a global variable:
PHP Code:
$_ENV['mytestzeststring'] = 'This Website Is Undergoing Tests';
So this should load immediately, right? It is the first declaration and assignment of the variable and so all of the following php files shoud understand this declaration, right?
Well, wrong. It did not work. Maybe it did not work because it is not what I am used to. in wp-login.php I had this declaration:
PHP Code:
print $_ENV['mytestzeststring'];
and nothing was printed. But, on the other hand, if I declared and assigned the global at the top of wp-login.php as i did in index.php, then it works.
Is there really such a thing as globals in PHP? I think maybe I am assuming that it should work the same way that globals work in compiled code and PHP is not the same kind of animal. It is interpreted on the server rather than actually running on the server. Maybe I need to code something much mor robust. I am hoping to avoid this but I am thinking that eventually I will have to grab the IP address from the user and use that to indicate a more one-to-one interface. Then I would use that IP address and store it in My SQL as a true global variable that can be read throughout the web site. Please tell me that this is not necessary.