You are here: Re: require_once doesn't work, "cannot redeclare class..." « PHP Programming Language « IT news, forums, messages
Re: require_once doesn't work, "cannot redeclare class..."

Posted by Tommy Gildseth on 02/24/06 22:11

Kimmo Laine wrote:

> I'm flipping my wig here, people. I'm using classes and making each class
> a file. when I'm including dependet classess, I use require_once to avoid
> multiple declarations - yet they happen. I put debug_print_backtrace in
> the file to see how it is included, and here's the output:
> #0 require_once() called at [\eKirje.textGrid.class.php:4]
> #1 require_once(\eKirje.textGrid.class.php) called at
> [\lasku.eKirjeLasku.class.php:3]#0 require_once() called at
> [\eKirje.kanava.class.php:3]
> #1 require_once(\eKirje.kanava.class.php) called at
> [\eKirje.EPL8.class.php:3]
> #2 require_once(\eKirje.EPL8.class.php) called at
> [\eKirje.kirje.class.php:3]
> #3 require_once(\eKirje.kirje.class.php) called at
> [\lasku.eKirjeLasku.class.php:5]
> <br />
> <b>Fatal error</b>: Cannot redeclare class boxcontainer in
> <b>\eKirje.boxcontainer.class.php</b> on line <b>5</b><br />As you see, it
> does get required twice regardless of the use of require_once in each
> call. And eventually the class gets declared again. My fix for the problem
> was to use
>
> if( !in_array('boxcontainer', get_declared_classes()) ) {
> require_once('eKirje.boxContainer.class.php');
> }
>


Trying to decipher that backtrace, it looks to me like you are including
several different class files. Does any of those depend on the
Kirje.boxcontainer.class.php, and include it on it's own? Could it be that
you at some other place are including the file using plain include or
require?


--
Tommy
http://design.twobarks.com/

 

Navigation:

[Reply to this 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

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