Variable Scope of Files Included Within Functions
From: Deane Barker (deane_at_slingandrock.com)
Date: 10/29/04
- Next message: Gordon Burditt: "Re: Uploading images to mysql database"
- Previous message: Wakeley Purple: "Re: How to make string of numbers shorter?"
- Next in thread: Tony Marston: "Re: Variable Scope of Files Included Within Functions"
- Reply: Tony Marston: "Re: Variable Scope of Files Included Within Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Oct 2004 19:51:28 -0700
I have a function that selects a file to include, then includes is.
The file is including within the function, like so:
function include_file($file_name)
{
[lots of logic here to figure out the path...]
require $file_name;
return;
}
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
function.
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
file.)
Deane
- Next message: Gordon Burditt: "Re: Uploading images to mysql database"
- Previous message: Wakeley Purple: "Re: How to make string of numbers shorter?"
- Next in thread: Tony Marston: "Re: Variable Scope of Files Included Within Functions"
- Reply: Tony Marston: "Re: Variable Scope of Files Included Within Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|