Solved

Globalise all varibles

Posted on 2003-12-09
5
314 Views
Last Modified: 2006-11-17
i have different complex functions that i have made into functions from normal code, and i dont want to go thru the funtion and globalise the varibles individually, so does anyone no how to globalise all varibles???? i would really appreachiate an answer?
0
Comment
Question by:RavenClaw
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:shmert
Comment Utility
extract($_GLOBALS);

this will put all the global variables into the current namespace for the function you are in.  It is also not a very efficient way to go, since it will create a copy of the entire $_GLOBALS array every time the function is called.
0
 

Author Comment

by:RavenClaw
Comment Utility
erm tried that just
but php error:
Warning: extract(): First argument should be an array
:\
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 370 total points
Comment Utility
the name of the array is $GLOBALS and not $_GLOBALS

extract($GLOBALS)
0
 

Author Comment

by:RavenClaw
Comment Utility
brilliant thanks thats saved me a lot of time :)
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
nice to see you happy, but I don't think it will save your script a lot of time.

The following will probably be more efficient, since it uses references instead.

foreach(array_keys($GLOBALS) as $k){
  $$k =& $GLOBALS[$k];
}

having that said I haven't tested it.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now