|  | Posted by Kimmo Laine on 02/27/06 08:58 
"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.
 
 
 Well... now I'm going out of my mind. Now it actually works. I don't know
 what I've changed, but for some reason now it all works perfectly. As
 someone suggested, it might have been a problem with the casing, ie.
 different casing in the filename, since at some point I copied the require
 statement from the other to the other, and later it started working. I gotta
 try to find an earlier copy from backups to see if it was a case of cases
 indeed.
 
 By the way, someone asked about the versio, I'm running PHP 5.0.5 with IIS6
 on a Windows 2003 Server.
 
 Thank you all for replying. I'll let you know if I can backtrace the
 problem, but at the moment I strongly suspect that it actually was something
 like spelling it require_once('eKirje.boxContainer.class.php'); in one file
 and require_once('eKirje.boxcontainer.class.php'); in the other. Blasted
 case-insensitive filesystem. In a *nix server this wouldn't have happened,
 since case matters in filenames.
 
 --
 "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviφ
 spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
 [Back to original message] |