Reputation: 12957
I'm using PHP 7.2.3 on my machine that runs on Windows 10.
I've installed PHP using latest version of XAMPP.
I come across following text from PHP Manual :
$_SERVER is just one variable that PHP automatically makes available to you. A list can be seen in the Reserved Variables section of the manual or you can get a complete list of them by looking at the output of the phpinfo() function.
In the above text from PHP manual it has been clearly said that I can see the complete list of such variables which PHP automatically makes available to my script.
When I observed the output of phpinfo();
I could only see the entire array of $_SERVER[]
superglobal variable. I couldn't see any other such predefined superglobal variables in the output of phpinfo();
Can I say this is a mistake in PHP manual?
Or can I say the manual is saying the thing rightly but I'm not able to get it and see the other predefined superglobal variables?
Please someone help me out in this regard.
Thank You.
Upvotes: -2
Views: 977
Reputation: 13
print_r($GLOBALS);
alone will give you the long list of all the global variables (both PHP and your own) available to any given part of your app you are in at that moment!
If you put everything into a function and call it when you are looking for something specific, it can make an awesome dev tool.
function whats_available(){
echo 'CONSTANTS:';
get_defined_constants(); //- Gets all constants
echo '<br/>';
echo 'FUNCTIONS:';
get_defined_functions(); //- Gets all functions
echo '<br/>';
echo 'VARIABLES:';
get_defined_vars(); //- Gets all variables
echo '<br/>';
echo 'CLASSES:';
get_declared_classes(); //- Gets all classes
echo '<br/>';
echo 'GLOBAL VARIABLES:';
print_r($GLOBALS);
}
whats_available();
Upvotes: 0
Reputation: 2201
There is a function called get_defined_vars() which does exactly what you want.
There are even more of them:
I couldn't see any other such predefined superglobal variables in the output
Screw what i said about this earlier. You are right, doc says
phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.
It should be noted, that you find GET, POST and COOKIE in $_REQUEST and not in their array respectivly.
If you only want to get the super globals from phpinfo, try following:
phpinfo(INFO_VARIABLES);
Upvotes: 0