Part of the EllisLab Network
   
 
1.5.1 not trapping “Cannot redeclare class” errors
Posted: 25 November 2006 04:30 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

Transferring my app code from 1.5.0.1 to 1.5.1, I find “Fatal error: Cannot redeclare class” is halting progress. It is correct that a class is being loaded more than once, but CI used to trap this scenario and forgive me.

Profile
 
 
Posted: 25 November 2006 08:20 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

Rick, I think you need to take another look at this loop from _ci_load_class() in Loader.php.

foreach (array(ucfirst($class), strtolower($class)) as $class)


I’m not sure I have the best answer, but by fiddling with this structure I can cure my problem above.
For a start, it seems generally bad practice to give the actionable variable the same name you started with ($class, in this case).
Secondly, although you are using array elements derived from ucfirst($class), you are subsequently using ucfirst($class) again which seems redundant.

Profile
 
 
Posted: 27 November 2006 03:18 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

Fearless pioneers of 1.5.1 seem pretty thin on the ground in here. Starts talking to self. Realises self isn’t listening. La di da, la di da, la di da.

Profile
 
 
Posted: 28 November 2006 11:30 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

For what it’s worth, I’m listening…  :D Though I’ve not run into this problem.

Profile
 
 
Posted: 29 November 2006 05:19 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006
Vanceone - 28 November 2006 11:30 PM

For what it’s worth, I’m listening…  :D Though I’ve not run into this problem.

Thanks for the company, anyway!
Are you redeclaring any classes?

Profile
 
 
Posted: 01 December 2006 01:23 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

The code:

<?php
class Example extends Controller {
    
function Example()
    
{
        parent
::Controller();
    
}
    
    
function index() {
       $this
->load->library('factory') ;
       
$this->load->library('factory') ;

    
}
}
?>


The result:

Fatal error: Cannot redeclare class factory in ....\system\application\libraries\factory.php on line 17

The culprit:  _ci_load_class() in Loader.php.

Why has no-one else encountered this?

Profile
 
 
Posted: 02 December 2006 02:01 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

Hmm.  I’m reloading a model or two, but I always load it with a different name, so I’m not experiencing this one.  Why are you reloading a library anyway?

Profile
 
 
Posted: 04 December 2006 02:18 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  351
Joined  07-25-2006

This isn’t a bug with trapping, it’s a bug with the way loader works. See this bug: http://codeigniter.com/forums/viewthread/46986/

 Signature 

me and some random code, hosted by dh. and a blog too! ++ dead bugs

Profile
 
 
Posted: 04 December 2006 01:08 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

Thank you, Shadowhand.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66415 Total Logged-in Users: 36
Total Topics: 84757 Total Anonymous Users: 2
Total Replies: 454849 Total Guests: 236
Total Posts: 539606    
Members ( View Memberlist )