Jump to content

Trying to understand how $GLOBALS works.


atrum

Recommended Posts

I have been trying to better understand how php works on a more in depth level, and recently I have been tinkering with arrays.

 

Using print_r() I have been studying the $GLOBAL array, and I found something I can't seem to find an explanation for.

 

In my $GLOBALS array there are variables I have set in a configuration file, but never actually made into globals.

 

Take the following code, and its output for example.

 

		echo "<pre>";
		echo print_r($GLOBALS);
		echo "</pre>";

 

The output:

Array
(
    [GLOBALS] => Array
*RECURSION*
    [_POST] => Array
        (
        )

    [_GET] => Array
        (
        )

    [_COOKIE] => Array
        (
            [phpSESSID] => fai4rtfgdt6o6iaihh62d0pa15
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [HTTP_HOST] => DOMAIN
            [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
            [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
            [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
            [HTTP_ACCEPT_ENCODING] => gzip,deflate
            [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
            [HTTP_KEEP_ALIVE] => 115
            [HTTP_CONNECTION] => keep-alive
            [HTTP_REFERER] => http://DOMAIN/test.php
            [HTTP_COOKIE] => PHPSESSID=fai4rtfgdt6o6iaihh62d0pa15
            [HTTP_CACHE_CONTROL] => max-age=0
            [CONTENT_TYPE] => application/x-www-form-urlencoded
            [CONTENT_LENGTH] => 67
            [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
            [sERVER_SIGNATURE] => 
            [sERVER_SOFTWARE] => Apache
            [sERVER_NAME] => DOMAIN
            [sERVER_ADDR] => IPADDRESS
            [sERVER_PORT] => 80
            [REMOTE_ADDR] => 198.65.168.24
            [DOCUMENT_ROOT] => /home/USER/www/DOMAIN
            [sERVER_ADMIN] => webmaster@DOMAIN
            [sCRIPT_FILENAME] => /home/USER/www/DOMAIN/test.php
            [REMOTE_PORT] => 43272
            [GATEWAY_INTERFACE] => CGI/1.1
            [sERVER_PROTOCOL] => HTTP/1.1
            [REQUEST_METHOD] => POST
            [QUERY_STRING] => 
            [REQUEST_URI] => /test.php
            [sCRIPT_NAME] => /test.php
            [php_SELF] => /test.php
            [REQUEST_TIME] => 1286050077
        )

    [date] => October 2, 2010
    [db_date] => 10/02/2010
    [error] => Array
        (
        )

)
1

 

The 3 items at the bottom.

 

    [date] => October 2, 2010
    [db_date] => 10/02/2010
    [error] => Array

 

Were set inside of a php config file. My question is, how did they end up in the $GLOBALS array?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.