Home  |  Linux  | Mysql  | PHP  | XML
From:Peter Lind Date:Thu Sep  2 11:55:17 2010
Subject:Re: Re: require_once
On 2 September 2010 13:20, Jangita <jangita@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>
Navigate in group php.general at sever news.php.net
Previous Next


Your recent visits
Re: cannot figure out permissions for fopen/fwrite
Re: [PHP] Split up Date Range
Split up Date Range
Re: [PHP] Select and compare problems still ...
Re: [PHP] Select and compare problems still ...



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants