Reply to Re: require_once doesn't work, "cannot redeclare class..."

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация