[How do I deal with GLOBALS?] - Computers



Search Tech-Forums - link takes you to our Forum's search page.

Note: The following is only a text archive!


To view the actual forum discussion, please visit our website at http://www.tech-forums.net

Pages:1



How do I deal with GLOBALS?

(Click here to view the original thread with full colors/images)



Posted by: datapimp

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..



Posted by: office politics

[php]
echo $_GLOBALS['basic_url'];
[/php]

show all global vars
[php]
foreach ($_GLOBALS as $key => $value) {
echo $key." - ".$value."<BR><BR>";
}
[/php]





vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited.


PPC Management
vB Easy Archive Final - Created by Xenon