Jump to content

Globalizing a Function's Scope Within a Function


iwato

Recommended Posts

Question: How does one get a function inside a function to behave as if it were in the global scope?Problem: If one calls the get_defined_vars() function inside a function, it returns the variables defined within the scope of the function in which it is called. In and of itself this is pretty cool; however, I want the function to obtain within the function what it would normally obtain, if it were called within the global scope -- in short, all variables.Roddy

Link to comment
Share on other sites

have it call a function in the global scope that calls get_defined_vars() and returns the results?

Link to comment
Share on other sites

have it call a function in the global scope that calls get_defined_vars() and returns the results?
I am not sure what to what noun the pronoun "it" in the above sentence refers, but unless the get_defined_vars() function is called in the global scope, it will not provide the data that I seek. The idea is to upgrade the get_defined_vars() function by processing data obtained from the get_defined_vars() function within the upgrading function. So, I need to know how to obtain the data from the get_defined_vars() function, as if the function were called in the global scope. If I have to call the get_defined_vars() function separately from the function, then I have not upgraded the function -- only the data derived from it.Roddy
Link to comment
Share on other sites

I am not sure what to what noun the pronoun "it" in the above sentence refers, but unless the get_defined_vars() function is called in the global scope, it will not provide the data that I seek. The idea is to upgrade the get_defined_vars() function by processing data obtained from the get_defined_vars() function within the upgrading function. So, I need to know how to obtain the data from the get_defined_vars() function, as if the function were called in the global scope. If I have to call the get_defined_vars() function separately from the function, then I have not upgraded the function -- only the data derived from it.Roddy
'it' is the function in question you were alluding to in your post.
How does one get a function inside a function to behave as if it were in the global scope?
so your function calls another function (global function) that's in the global scope. global functions job is to call get_defined_vars() and return the results back to 'it', the function making the call to global function.this is just an idea, i have no idea if it's the best way to do it, or if it will even work. just kinda popped into my head after reading your post.
Link to comment
Share on other sites

There's not a way to specify the scope of the function when you call it, like there is in Javascript. You can either specify the variables you want as global, or use $GLOBALS to access them. All global variables are defined in the $GLOBALS array.

Link to comment
Share on other sites

There's not a way to specify the scope of the function when you call it, like there is in Javascript. You can either specify the variables you want as global, or use $GLOBALS to access them. All global variables are defined in the $GLOBALS array.
Yes, I had forgotten. It has been so long.Many thanks, JSG.Roddy
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...