Solved

Globalise all varibles

Posted on 2003-12-09
5
317 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 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

806 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