NYCPHP Meetup

NYPHP.org

[nycphp-talk] Dynamically write functions

Frank Wong frank_wong2 at informationideas.com
Fri May 13 13:37:11 EDT 2005


Dan Cech wrote:

> Frank,
>
> What you could do is to make a helper function like:
>
> function &get_globals()
> {
>   return array(
>     'var1' => $GLOBALS['var1'],
>     'var2' => $GLOBALS['var2']
>   );
> }
>
> then use:
>
> function myfunc()
> {
>   extract(get_globals(),EXTR_REFS);
>
>   // code
> }
>
> This way you will have all the same access to the variables that you 
> had before, and full control over which variables are available.
>
I like that a lot.  This is the method I'm going to go with.  Thank you 
very much for the pointers.





More information about the talk mailing list