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

  • Home
  • SEARCH
  • 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 9006277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:22:02+00:00 2026-06-16T01:22:02+00:00

I recently starting writing a custom MVC framework in PHP. It’s basically a learning

  • 0

I recently starting writing a custom MVC framework in PHP. It’s basically a learning exercise.

My classes are located in the following directories:

  • system/libraries/
  • system/controllers/
  • system/models
  • application/libraries/
  • application/controlers/
  • application/models

I’m not using namespaces because I can’t figure out how to instantiate controllers using namespaces and Apache 2 handler style URLs (controller/action/id). I created a Bootstrap class to autoload my other classes:

class Bootstrap
{
  public function autoloadClasses($class)<br/>
  {
    $class .= '.php';

    $classDirectories = array(
        SYSTEM_LIBS_DIR,
        SYSTEM_CONTROLLERS_DIR,
        SYSTEM_MODELS_DIR,
        APPLICATION_LIBS_DIR,
        APPLICATION_CONTROLLERS_DIR,
        APPLICATION_MODELS_DIR
    );

    foreach ($classDirectories as $classDirectory) {
        $directoryIterator = new DirectoryIterator($classDirectory);
        foreach($directoryIterator as $file) {
            if ($file == $class) {
                include $classDirectory . $class;
                break 2;
            }
        }
    }

  }


  public function register()
  {
    spl_autoload_register(array($this, 'autoloadClasses'), true);
  }


  public function init()
  {
    $this->register();
    $loader = new Loader($_GET);
    $controller = $loader->createController();
    $controller->executeAction();
  }
}

It works fine. However, I know I should really be using the implementation recommended by PSR-0:

https://gist.github.com/221634

However, I can’t figure out how to get it to work without namespaces. It looks like the namespace is an optional pararmeter. However, if I do the following, nothing happens — not even an error in the Apache logs:

$libLoader = new SplClassLoader('', 'system/libraries');
  • 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-16T01:22:03+00:00Added an answer on June 16, 2026 at 1:22 am

    The goal of PSR-0 was to try and specify how external third-party library classes should be named, and where the files containing those classes should live on disk. This goal was accomplished, and from a high level, it’s not too bad of a thing. Interopability and not stepping all over other libraries is a good thing.

    Your directory layout and class naming scheme doesn’t mesh with PSR-0, which means SplClassLoader is going to be nigh-useless for you.

    You have two options:

    1. Rename all of your classes, shuffle them into a namespace hierarchy, and refactor the rest of the code that needs to worry about it, or
    2. Don’t use SplClassLoader and write your own autoloader.

    If you’re building a library intended for external distribution, it’ll be a good idea to make yourself PSR-0 compliant, as it’s pretty darn simple, logical and painless.

    If you’re building your own app for your own use and don’t intend it as a library, then you are under no requirement to do all of that work, and you shouldn’t, because it’d be silly. This looks like it’s the case, so I can end with a big fat: don’t bother.

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

Sidebar

Related Questions

Recently I've gotten sick and tired of writing release notes and I'm really starting
I've recently starting learning java web development and I want to learn/understand: What constitutes
I recently started learning HTML/CSS and am starting to get really frustrated with font
I'm recently starting to learn Java and have had success writing and compiling my
I had recently starting learning openGLES and right now I had gone through some
Instead of starting to code in Matlab, I recently started learning R, mainly because
This work great to delete php, txt and images but I recently starting using
I recently started learning objective-C and cocoa. I'm slowly starting to learn about memory
I recently starting learning test driven development, namely MXUnit, and I love the idea's
As a fairly experienced ASP.Net developer just recently starting using MVC, I find myself

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.