Let's say I have a page with 10 functions. Each function uses $IncVar from an included file.
What's a better way of bringing in $IncVar so that that it works as a local scope variable? Should I include the file once at the top of the page, and define $IncVar as a global variable within each function, or should I include the file within each function?
I figure that it probably doesn't make much of a difference if I only use one of the functions. But in my case, I will be using most of the functions in one script. So, I wasn't sure which method would be more effecient.
Just trying to learn what works better. Thanks.
effeciency of global variable vs includes in a function?
Moderator: General Moderators
Re: effeciency of global variable vs includes in a function?
Define the vars within the function. That's the fastest way of doing. My benchmarks show that to be the case and Sterling Hughes (one of the PHP developers) states as much. Including a file for each function call is not needed.Swede78 wrote: What's a better way of bringing in $IncVar so that that it works as a local scope variable? Should I include the file once at the top of the page, and define $IncVar as a global variable within each function, or should I include the file within each function?
Cheers,
BDKR