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 4071096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:42:47+00:00 2026-05-20T16:42:47+00:00

I currently am building my own PHP framework and am creating a lot of

  • 0

I currently am building my own PHP framework and am creating a lot of directories to store my classes in.

This is my current autoload function:

function __autoload($className)
{
    $locations = array('', 'classes/', 'classes/calendar/', 'classes/exceptions/', 'classes/forms/', 'classes/table/', 'classes/user', 'pages/', 'templates/');
    $fileName = $className . '.php';

    foreach($locations AS $currentLocation)
    {
        if(file_exists($currentLocation . $fileName))
        {
            include_once ($currentLocation . $fileName);
            return;
        }
    }
}

Now in my main class file I do have all of the necessary classes already included so that they won’t have to be searched for.

Here are my questions:

  1. Is this function efficient enough? Will there be a lot of load time or is there a way for me to minimize the load time?
  2. Is include_once() the way that I should go about including the classes?
  3. Is there a way that I could write the function to guess at the most popular folders? Or would that take up too much time and/or not possible?
  4. Would namespaces help me at all? (I am reading and learning about them right now.)
  • 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-05-20T16:42:47+00:00Added an answer on May 20, 2026 at 4:42 pm
    1. This is answered very well here: autoload and multiple directories
    2. You should probably go with require, for two reasons: a) you don’t need to have PHP track if the file has been already included, because if it has it won’t need to call __autoload in the first place and b) if the file cannot be included you won’t be able to continue execution anyway
    3. The answer for point 1 covers this
    4. Not necessarily; you need some namespace-like mechanism to implement faster loading (to only look where you have to) but you can fake it if necessary without using real namespaces

    For reference, the interaction between __autoload and namespaces is documented here.

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

Sidebar

Related Questions

I am currently building in Version 3.5 of the .Net framework and I have
I am building an application currently in PHP and I am trying to decide
I am building a modular framework for a PHP MVC site. I am using
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I'm building my own framework, and I'm trying to pass a parameter to a
This project is in PHP, but is fairly language agnostic. I'm building a project
I'm building a front-end content editing module for my own framework using a WYSIWYG
I am currently building a gallery web application using php. I am currently developping
I'm currently building a Java app that could end up being run on many
I am currently building an internal web application used in a factory/warehouse type location.

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.