Solved

Globalise all varibles

Posted on 2003-12-09
5
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 370 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

Suggested Solutions

Title # Comments Views Activity
&& operators not performing required logic 8 41
How to close my php post page. 3 42
htaccess add www, redirect to https, keep query string 17 57
Google Recaptcha 13 53
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

738 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