Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Globalise all varibles

Posted on 2003-12-09
5
Medium Priority
?
322 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
ID: 9906613
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
ID: 9906801
erm tried that just
but php error:
Warning: extract(): First argument should be an array
:\
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 1480 total points
ID: 9906869
the name of the array is $GLOBALS and not $_GLOBALS

extract($GLOBALS)
0
 

Author Comment

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

Expert Comment

by:aolXFT
ID: 9906975
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

926 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