Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » How do I deal with GLOBALS?
Closed Thread
Old 01-20-2007, 04:33 AM   #1 (permalink)
 
Newb Techie

Join Date: Dec 2006

Posts: 23

datapimp

Default How do I deal with GLOBALS?

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..
datapimp is offline  
Old 01-21-2007, 08:04 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default

PHP Code:
echo $_GLOBALS['basic_url']; 
show all global vars
PHP Code:
foreach ($_GLOBALS as $key => $value) {
  echo 
$key." - ".$value."

"
;


office politics is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On