tags:

views:

881

answers:

6

Hello,

is there a way to create my own custom superglobal variables like $_POST and $_GET?

+6  A: 

No. There are workarounds, but I'm not going to tell them to you as globals are bad. :)

Ionuț G. Stan
This has got to be one of the most foolish answers I have ever seen on SO. You ought to be ashamed. Downvoted.
abrahamvegh
A: 

Not really. though you can just abuse the ones that are there if you don't mind the ugliness of it.

rikh
A: 

simple!

$GLOBALS['_MYVAR'] = 'foo';

print_r($_MYVAR);
James C
$_MYVAR won't be visible inside functions, unless you import it using the global statement, or accessing it as a key of the $GLOBALS superglobal.
Ionuț G. Stan
+2  A: 

Static class variables can be referenced globally, e.g.:

class myGlobals {

   static $myVariable;

}

function a() {

  print myGlobals::$myVariable;

}
Scott Reynen
A: 

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'];
}
OneNerd
A: 

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.

Ian Warner