create superglobal variables in php?
Solution 1:
Static class variables can be referenced globally, e.g.:
class myGlobals {
static $myVariable;
}
function a() {
print myGlobals::$myVariable;
}
Solution 2:
Yes, it is possible, but not with the so-called "core" PHP functionalities. You have to install an extension called runkit7: Installation
After that, you can set your custom superglobals in php.ini as documented here: ini.runkit.superglobal
Solution 3:
I think you already have it - every variable you create in global space can be accessed using the $GLOBALS
superglobal like this:
// in global space
$myVar = "hello";
// inside a function
function foo() {
echo $GLOBALS['myVar'];
}