Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Deane Barker
October 29, 2004, 12:51 am
rate this thread
The file is including within the function, like so:
[lots of logic here to figure out the path...]
My problem is that the file gets included *within* the function, so
all the code in the file inherits the function's scope. Any variables
declared in the include file are not global -- they're local to that
Is there any way around this? Is there anything I can put in the
included file or in the function to make sure that variables declared
within it are global? (I can't just reference the variables before
the require, because I have no way of knowing what's in the include
Re: Variable Scope of Files Included Within Functions
Use the function to determine the filename, but instead of include()ing it
within the function just return the name to the calling script. When the
calling script issues the include() any variables will then be within the
scope of that script, not the function.
Easy when you know how.