| 
	
 | 
 Posted by Tony Marston on 02/25/06 11:55 
I have come across the same problem in my own framework. The way I got  
around it was to use class_exists() before the require() statement, so if  
the class definition already existed I did not load it again. 
 
--  
Tony Marston 
 
http://www.tonymarston.net 
 
 
 
"Kimmo Laine" <spam@outolempi.net> wrote in message  
news:HiALf.4069$wU5.1503@reader1.news.jippii.net... 
> 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'); 
> } 
> 
> in the files and now it works, but I'm just totally baffeld of why this is  
> happening? How come the require_once fails to function? Am I missing  
> something here? 
> 
> I made the simplest test case where I had four files where in the first of  
> them I declare a class, then require_once it to two other files and then  
> finally require_once the two files to a fourth file. In this case I did  
> not get redeclaration errors, for some reason it worked okay then, the  
> class was declared only one and it worked okay. 
> 
> --  
> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviφ 
> spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg) 
>
 
[Back to original message] 
 |