|
Posted by Erwin Moller on 02/24/06 16:12
Kimmo Laine wrote:
<snip>
>
> No, absolutely not. I've got a file A.php containing class A and files
> F.php and G.php which both have require_once("A.php"); Then I have a page
> D.php which has require_once("G.php"); and require_once("F.php");
> resulting the multiple declaration, since they both eventually require
> A.php, which they shouldn't since I've used require_once...
>
aha. That is the problem then, but it is subtile.
This what PHP.net says about require_once():
[quote]
The require_once() statement includes and evaluates the specified file
during the execution of the script. This is a behavior similar to the
require() statement, with the only difference being that if the code from a
file has already been included, it will not be included again. See the
documentation for require() for more information on how this statement
works.
[/quote]
So you might expect that PHP is counting the number os time a certain file
is required, but that is NOT what it says: It only look for THE SAME FILE.
The difference might not seem big, but this is excactly what causes your
problem: Your include is used in different files, and thus included every
time, hence the multiple declaration.
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|