Re: include_once() and require_once() in function
- From: Jamie Furness <jamie+usenet@xxxxxxxxxxxxx>
- Date: Mon, 29 Sep 2008 21:17:21 +0100
Andrew G. Koptyaev wrote:
Is I can use include_once() or require_once() in function or only include()?
If you use include_once the file will only be included the first time the function is called, if you use include it will be included each time the function is called. (require and require_once follow the same principle obviously.)
You need to consider what is in the file you are including, and what scope it should have. For example:
If the file you include sets some variables and you use include_once, the second time you call the function the file will not be included again, though the variables won't be already defined because their scope was only within the function.
However if the file you include defines a function and you use include, the second time you call the function you will get an error trying to redefine the function since it has global scope.
.
- References:
- include_once() and require_once() in function
- From: Andrew G. Koptyaev
- include_once() and require_once() in function
- Prev by Date: Re: Can't addFile() in SimpleTest Test Suite
- Next by Date: Re: A/B split testing on PHP built website
- Previous by thread: Re: include_once() and require_once() in function
- Next by thread: Manually setting session ids
- Index(es):
Relevant Pages
|