I am learning PHP from w3schools' PHP Tutorial.
While learning PHP I came across the concept of predefined global variables i.e. Superglobals.
In a curiosity to understand "Superglobals" more deeply I wrote the following code and executed it in a browser on my local machine(i.e.localhost) :
<!DOCTYPE html>
<html>
<body>
<?php
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
?>
</body>
</html>
I got following output in a browser :
Array
(
[_GET] => Array
(
)
[_POST] => Array
(
)
[_COOKIE] => Array
(
[toWorkNormally] => 1
)
[_FILES] => Array
(
)
[GLOBALS] => Array
*RECURSION*
)
The above output has created many doubts in my mind as follows :
- As per my knowledge in PHP there are nine types of
superglobals (predefined PHP global variables) viz.
$GLOBALS, $_SERVER, $_REQUEST, $_POST, $_GET, $_FILES, $_ENV, $_COOKIE
and$_SESSION
then my doubt is what does the array elements from the predefined global array$GLOBALS
viz.[_GET], [_POST], [_COOKIE], [_FILES]
mean as they have their own independent existence as superglobals? - What is meant by
[toWorkNormally] => 1
from above array output? - What does mean by RECURSION in element
[GLOBALS]
and how to print those elements? - As the purpose of
$GLOBALS
array is to store variables declared by user globally then how this array has been pre-populated with some other values as I haven't declared any global variable in my code?
Note : I'm using "Microsoft Windows 10 Home Single Language" operating system on my machine. It's a 64-bit Operating System. I'm using latest edition of XAMPP with PHP 7.0.13 and HTTP Apache web server v.2.4.23 for running the program locally. Also, please note that I have not defined any other variable as global or local in my code.