How do I deal with GLOBALS?

Status
Not open for further replies.

datapimp

Baseband Member
Messages
23
Hi all,

I read in php manual:

Quote:
Global variables: $GLOBALS
Note: $GLOBALS has been available since PHP 3.0.0.

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods.
So If You don't need to do a global $GLOBALS, how to deal with this $GLOBALS so that the variable exist in function.

I made example below:

Code:

<?php $basic_url = 'http://www.php.net'; $GLOBALS = ..........; function whatever() { echo $GLOBALS.....; } whatever(); // would print 'http://www.php.net' ?>


How to deal with the $GLOBALS so the above script will produce 'http://www.php.net' without making a global $GLOBALS.

Please advise..
 
PHP:
echo $_GLOBALS['basic_url'];

show all global vars
PHP:
foreach ($_GLOBALS as $key => $value) {
  echo $key." - ".$value."

";
}
 
Status
Not open for further replies.
Back
Top Bottom