Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:55:41+00:00 2026-06-10T05:55:41+00:00

im trying to understand the framework structure in CodeIgniter and i have just started

  • 0

im trying to understand the framework structure in CodeIgniter and i have just started and came up with this little misunderstanding .

so can somebody please help me under stand the following :-

1- why do they use a reference to pass an instance of the class … i mean why not just a simple variable ?

2- and why does the function store the name of the class in an array instead of a “string variable” (please dont judge my php terms as im the worst at it ).. ?!

static $_classes = array();
                   ^^^^^^^ this cloud be just ("") or am i missing something

here is the function so you wont go looking for it .

function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
    {
        static $_classes = array();

        // Does the class exist?  If so, we're done...
        if (isset($_classes[$class]))
        {
            return $_classes[$class];
        }

        $name = FALSE;

        // Look for the class first in the local application/libraries folder
        // then in the native system/libraries folder
        foreach (array(APPPATH, BASEPATH) as $path)
        {
            if (file_exists($path.$directory.'/'.$class.'.php'))
            {
                $name = $prefix.$class;

                if (class_exists($name) === FALSE)
                {
                    require($path.$directory.'/'.$class.'.php');
                }

                break;
            }
        }

        // Is the request a class extension?  If so we load it too
        if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
        {
            $name = config_item('subclass_prefix').$class;

            if (class_exists($name) === FALSE)
            {
                require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
            }
        }

        // Did we find the class?
        if ($name === FALSE)
        {
            // Note: We use exit() rather then show_error() in order to avoid a
            // self-referencing loop with the Excptions class
            exit('Unable to locate the specified class: '.$class.'.php');
        }

        // Keep track of what we just loaded
        is_loaded($class);

        $_classes[$class] = new $name();
        return $_classes[$class];
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:55:42+00:00Added an answer on June 10, 2026 at 5:55 am

    The key is the static keyword before $_classes = array();. This makes the $_classes array hold it’s value in between multiple calls to the function. Basically they use it as a local cache for the instantiated classes. For this purpose a string won’t work.

    See more about the static keyword in the manual.

    As for the reference returning, i think that’s php4 baggage, CI was supported on php4 until 2.x. You might find this blogpost helpful to see what was changed from php4 to php5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand Zend Framework 2. For that, I started with Ron Allen's
I am just getting into OOP and framework design. I have started by using
Trying to understand the Android framework model. I have an application that needs to
I am trying to understand the internals of how jquery framework is written and
I am trying to learn how Entity Framework works. I understand that EF SaveChanges
I'm trying to include the Sparkle framework in my application. I don't really understand
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Trying to understand Ruby a bit better, I ran into this code surfing the
I'm trying to understand some fundamental best practices using Entity Framework. My EDM design

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.