Is there a file where WordPress defines $GLOBALS
?
I’m just curious as to what WordPress uses it for and for what purpose.
That’s all!
Is there a file where WordPress defines $GLOBALS
?
I’m just curious as to what WordPress uses it for and for what purpose.
That’s all!
You must be logged in to post a comment.
I’m not sure if all of these are WordPress globals, but I did a quick grep type search of the WordPress files and tried to extract all the globals I could..
This is the list I compiled. It may not be perfect, but should *hopefully* represent a lot of the
$GLOBALS
keys that WordPress uses It won’t account for globalised variables that aren’t explicitly defined as$GLOBAL
, but still have global scope.If you wanted to get a better idea of everything inside the global array you could run something like the following to get a print out, because the above approach was obviously flawed since globals are defined in more than one way.
That should give you a more comprehensive list of variables in the global scope.
Hope that’s helpful. 🙂
Unfortunately, no.
Globals definitions are scattered throught the codebase.
There’s no documentation for most of them, either.
$GLOBALS
is an associative array containing references to all variables which are currently defined in the global scope. This is a PHP language tool.Global variables can be defined simply by creating a new item in the
$GLOBALS
array like this:WordPress Globals are used to share data across files. They are not defined in any specific place but you can find some of the most important ones here: http://codex.wordpress.org/Global_Variables
PHP makes it even easier to use
$GLOBALS
by allowing you to access the items by simply declaring it using theglobal
keyword.is the same as:
Please note, if you didn’t define
$foo
as global, it will not be linked to the global variable scope.Some further reading on this:
http://www.php.net/manual/en/reserved.variables.globals.php
If you try to print out all the
$GLOBALS
and get an error ‘allowed memory exceeded’ or something like that, than put this code inside functions.php: