On 2 September 2010 13:20, Jangita <jang...@jangita.com> wrote: > On 02/09/2010 12:59 p, Peter Lind wrote: >> >> Which wouldn't do anything seeing as file2.php has already been >> included by file1.php. > > Amazing! I didn't think that once you include a file; any other file > included also includes any earlier included files (if that makes any sence) > > I've always thought includes are local; I.e in order to use a function from > another file explicitly include that other file.
You're thinking about it from the wrong perspective. It's not a question of a file including another file into it's own space, it's a question of scope. If you're in the global scope, any file included will get included into the global scope. If you're in a local scope however, then other rules apply: variables in the file (that would normally be in the global scope if you just executed the file) will be in the local scope only, while classes and functions in the included file will be imported into the global scope. Also, require_once will require a file once only. Using it to require the same file again from anywhere else will fail to include the file - that's the whole point of _once. Regards Peter -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 </hype> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php