views:

179

answers:

2

I have a seperate PHP file I include that has a several important functions on it. I also have a file called variables.php which I include into each function so I can call some important variables too. Is there a way to just call variables.php at the top of the page, instead of inside each function manually? I just thought it would be easier if there was a way to do like a 'global' include or something.

+3  A: 

You can set auto_prepend_file in the INI or .htaccess file to automatically include a file.

konforce
do i just use ini_set to set it for the functions page only?
David
The auto_prepend_file only prepends it once BTW. At the beginning of the script.
Chacha102
`auto_prepend_file` will not solve the problem of variables being out of scope inside functions which I think is OPs original problem
Marek Karbarz
I probably misunderstood ... are you trying to import variables into a local function scope? If so, I wouldn't really recommend that. You'd (generally) be better off including the variables once and using `$GLOBALS[]` to access it. You could put all of the variables into a single array to limit name collisions (or a static class, etc).
konforce
+2  A: 

Well, if they are constant variables (AKA they don't change) you can define a constant instead

define("CONSTANT_NAME", "constant_value");

Or as of PHP5.3

const COSTANT_NAME="constant_value";

Then you can access them in every function

function test(){
    echo CONSTANT_NAME;
}
Chacha102