I tried the following code to create a superglobal variable using $GLOBALS.
test.php
<?php
$GLOBALS['test']='hello';
header("location:test3.php");
?>
Here is the test3.php
<?php
var_dump($GLOBALS);
echo $GLOBALS['test'];
?>
The output i get is
array(5) { ["GLOBALS"]=> *RECURSION* ["_POST"]=> array(0) { } ["_GET"]=>
array(0) { }["_COOKIE"]=> array(1) {"PHPSESSID"]=>string(26)"oer267anbfrrhtj64lpqrocdd3"}
["_FILES"]=> array(0) { } }
The $GLOBAL['test'] is not getting set.
But when I try var_dump in test.php,I find $GLOBAL array to have a key 'test' with value 'hello'.
What is the reason of this behaviour?
Also I wish to create a superglobal database connection object using the $GLOBAL.Is it recommended?