On Wed, 18 Feb 2004 15:44:10 +0100
hartmut@php.net (Hartmut Holzgraefe) wrote:
> it works for the first call to getFoo(),
> on any following call include_once
> will ignore "inc.php" as it was already
> included before, and as $foo is a local
> variable to getFoo() it won't exist in
> any but the first call
>
> remember that in PHP include is evaluated
> at runtime, not at compile time ...
Thanks for the reminder :) I thought about that at the first source of
the problem, but:
It works with php4. For instance this is widely used to include a given
file on demand, and only on demand.
I thought that in the context of getFoo (lost between 2 calls), it
should include it again.
In this simple case, it is not a problem, there is no global
"pollution". But in the case the included files contains a
class/function definition, you run in troubles. That's why I think the
behavioir should remain the same as with php4.
An alternative is to split all possible runtime datas to a different
file and not in the same file as the class/function declaration. But in
both cases that will break a lot of scripts around.
hth
pierre