Re: [PHP4BETA] Expected behavior?
| From: | php4 at developersdesk dot com | Date: | Mon, 01 May 2000 12:08:28 +0000 |
| Subject: | Re: [PHP4BETA] Expected behavior? | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-14282@lists.php.net to get a copy of this message | ||
Addressed to: Mark Constable <markc@renta.net>
php4beta@lists.php.net
** Reply to note from Mark Constable <markc@renta.net> Mon, 01 May 2000 21:39:34 +1000
>
> Wico de Leeuw wrote:
>
> > Put file 3 in include_path or supplie the full pathname
> > else php can not find the include file (Expected behavior)
> > also put a . into the include_path (when given an include path php will not
> > auto add the current dir)
> > (annoying behavior :)
>
> > At 02:52 1-5-2000 -0700, Seth Banks wrote:
> > >I have a page that requires a class file, and in that file (file 2) it
> > >requires another file (file 3). On the 1st required file I get an error on
> > >compile because php can't find file 3. File 1 lives in a different directory
> > >than file 2, which is causing the error.
>
> So does this mean that PHP will always pull any included file, and
> it's contents (vars, functions, paths), into it's global namespace of
> the original executing file (class'd or not) and not directly into the
> namespace of the calling file/script/class however many levels deep
> that might be ?
>
When you include/require a file it is as if the contents of that file
were placed in the outer file, at the location of the include/require.
That's all there is to it.
The second level includes go into the first level includes, which go
into the top level. When the code is interpreted it is treated like it
was one big file.
Included files do not always go into the global namespace. If you
include a file from within a function, the included code has the scope
of the function it was called from.
> If so then that's not intuitive and I'm wondering if there is reason
> to "flatten" out namespaces ? Is it a limitation of PHP, a legacy of
> old PHP3 bevaviour, or is there some real benefits to having this
> flattened namespace ? All else about PHP4 seems uber-groovy.
There is no magic to include/require. The effect of include/require is
the same as if you had typed the contents of the included file instead
of the include/require statement.
The difference between include and require is when they are processed.
Require happens before the code is interpreted. You can not affect
require based on the code around it.
Include happens as the code is run, you could include a different file
in each step of a loop, if you wanted to.
Rick Widmer
www.developersdesk.com