Structured display of All Variables in memory
to Get a structured display or list of, ALL variables in memory!
"The function, get_defined_vars(), returns a multidimensional array containing a list of all defined variables at that location in your program."
To get ALL variables, list ALL variables, display ALL variables, in memory and available at the point where you request it, your scope, (not just SESSION variables, everything ... except private function variables - invisible/unavailable externally).
To get more than just a string of names and values, but a readable, structured list, use
echo '< pre >';
print_r ( get_defined_vars() ) ;
echo '< /pre >';
For a long time, I have been displaying the variables in memory with
print_r( get_defined_vars() );
and getting a slammed, one line, hard to read, string of so many variables and values that wrapped around line after line. Now I have discovered that putting "pre" around it formats it with indenting even. Very nice. (above)
Even nicer, instead of print_r(), use var_dump(). It not only displays values in colors, it also displays the variable type (string, int, boolean, etc.) for each one.
echo '< pre >';
var_dump ( get_defined_vars() );
echo '< /pre >';
for me, it also displays boolean (false (0)) values that did not show up before. Only the boolean "true" ("1") was showing up for me. (I don't know if this is true of anyone else)
In all cases, the GLOBAL variables (almost all of them) are getting displayed twice - in my v5.2 anyway.
You might place get_defined_vars(), both inside and outside a function to see the difference.
or
echo '< pre >'. "This way you don't get rendered HTML." (if it's an issue)
htmlspecialchars(print_r(get_defined_vars(), true)).
'< /pre >';
< pre > print_r() example:
array(3) {
["greet"]=>
string(5) "howdy"
["mainframe"]=>
&object(XXXXX)#N (2) {
["_name"]=>
string(3) "Joe"
["requestTime"]=>
string(16) "2010-03-03 23:58"
}
["headerstuff"]=>
array(3) {
["title"]=>
string(36) "PWSDB: Programming WebSite DataBases"
["metaTags"]=>
array(2) {
["http-equiv"]=>
array(1) {
["content-type"]=>
string(24) "text/html; charset=utf-8"
}
["standard"]=>
array(2) {
["robots"]=>
string(13) "index, follow"
["keywords"]=>
string(20) "database programming"
}
}
["style"]=>
array(0) {
}
}
}
You can also display only session variables: print_r($_SESSION);
print_r($_POST);
print_r($_GET);
also see
get_defined_constants()
get_defined_functions()