David Mehler wrote:
> Hello,
> I've got probably a simple question on require_once. I've got a file
> that has require_once at the top of it pulling in another file of
> functions. Later on in this file I've got another require_once
> bringing in a second file. In this second file I have a function call
> to a function defined in the first files' top require_once functions
> file. I'm getting a call to undefined function.
> Should I change he require_once to require at the top of the first
> file to fix? I thought require_once meant it was in that file and
> anything pulled in later?
> Thanks.
> Dave.
Which wouldn't do anything seeing as file2.php has already been
included by file1.php.
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>
I've always thought includes are local; I.e in order to use a function
from another file explicitly include that other file.
--
Jangita | +256 76 91 8383 | Y! & MSN: jan...@yahoo.com
Skype: jangita | GTalk: jangita...@gmail.com
If i get you correctly
file1.php has a require_once to file2.php
then file 1.php has a require_once to file3.php
but file3.php calls a function in file2.php
answer would be to require_onec file2.php in file3.php
or?
The file is included properly, otherwise your script would halt.
You're likely looking at an issue of scope: the functions might be
included in a scope you don't expect them to be.
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.