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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:11:10+00:00 2026-06-11T06:11:10+00:00

I am developing a new application from scratch and I need to autoload files

  • 0

I am developing a new application from scratch and I need to autoload files recursively.
However, I need to use namespace like Zend Framework.

For example, LibraryName_Http_Request will load LibraryName/Http/Request.php file.
Whatsoever I’ve tried, I can only use LibraryName_Http_Request class if I name the file LibraryName_Http_Request.php.

I can’t figure out how to change my code so that i can load class files in the same Zend fashion…

Here is my code:

class Autoloader
{

    public function __construct()
    {
        spl_autoload_register( array( $this, 'autoload' ) );
    }

    public function autoload( $class )
    {
        $iterator = new RecursiveDirectoryIterator( LIBRARY_PATH );

        foreach( new RecursiveIteratorIterator( $iterator ) as $file=>$meta ) {

            if( ( $class . '.php' ) === $meta->getFileName() ) {

                if( file_exists( $file ) ) {
                    require_once $file;
                }
                break;
            }
        }        

        unset( $iterator, $file );
    }

}
  • 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-11T06:11:11+00:00Added an answer on June 11, 2026 at 6:11 am

    You should check out the PSR-0 which does what you want. You can find a link to PSR-0 loader implementation at the end of the recommendation.


    Update: Since you are using PHP 5.2, the above loader doesn’t fully fit to your needs. Here is a simple autoloader I wrote based on PSR-0 without namespace support:

    class SimpleClassLoader
    {
        /**
         * Installs this class loader on the SPL autoload stack.
         */
        public function register()
        {
            spl_autoload_register(array($this, 'loadClass'));
        }
    
        /**
         * Uninstalls this class loader from the SPL autoloader stack.
         */
        public function unregister()
        {
            spl_autoload_unregister(array($this, 'loadClass'));
        }
    
        /**
         * Loads the given class or interface.
         *
         * @param string $className The name of the class to load.
         * @return void
         */
        public function loadClass($className)
        {
            require str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
        }
    }
    

    Then register the loader:

    $loader = new SimpleClassLoader();
    $loader->register();
    

    Now referencing LibraryName_Http_Request will include LibraryName/Http/Request.php.

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

Sidebar

Related Questions

I am developing a new web application from scratch. I need to provide multi-language
I start developing a new Android application from scratch these days. The company I
While developing a navigation based application from scratch, I added some new uisubview Controller
I'm developing a web application for a new service, starting from Firefox 3.5. The
Im trying to learn how to set up a Zend framework web application from
My team is developing a new DotNetNuke web application and would like to know
I'm developing a new Java desktop application and would like to include a crash
I'm developing a new SOA system right now, and would like to use WSDL2.0,
I'm developing a new experimental web-application framework, and I decided to give RESTful some
We are departing from our typical native application development and are developing some new

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.