Hello,
is there a way to create my own custom superglobal variables like $_POST and $_GET?
Hello,
is there a way to create my own custom superglobal variables like $_POST and $_GET?
No. There are workarounds, but I'm not going to tell them to you as globals are bad. :)
Not really. though you can just abuse the ones that are there if you don't mind the ugliness of it.
Static class variables can be referenced globally, e.g.:
class myGlobals {
static $myVariable;
}
function a() {
print myGlobals::$myVariable;
}
I think you already have it - every variable you create in global space can be accessed using the $GLOBALS suberglobal like this:
// in global space
$myVar = "hello";
// inside a function
function foo() {
echo $GLOBALS['myVar'];
}
You can also use the Environment variables of the server, and access these in PHP This is a good way to maybe store global database access if you own and exclusively use the server.