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

The Archive Base Latest Questions

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

I am just learning how to use spl_autoload_register I have a folder structure that

  • 0

I am just learning how to use spl_autoload_register

I have a folder structure that looks like this:

lib/projectname/home/homepage.php

so if I include the file like this it works:

include("lib/projectname/home/homepage.php");
$home = new homepage();

I have added in an autoload.php file which looks like this:

function myclass($class_name) {
   $class_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
   require_once($class_name);
 }

spl_autoload_register('myclass');

Now if I try to use the class I am referencing it like this:

require_once("autoload.php");

$home = new lib_projectname_home_homepage;

when i do this, i get the following error:

Fatal error: Class 'lib_projectname_home_homepage' not found

So it appears as if the loading of the class file is working, but its not finding the class inside the file?

The actual homepage.php file looks like this:

class homepage {

    function __construct(){

        echo "homepage";
    }

}

What do I need to change in order to make this work properly?

  • 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-17T01:25:17+00:00Added an answer on June 17, 2026 at 1:25 am

    change

    class homepage {
        function __construct(){
            echo "homepage";
        }
    }
    

    to

    class lib_projectname_home_homepage {
        function __construct(){
            echo "homepage";
        }
    }
    

    or change:

    require_once($class_name);
    

    to

    require_once('lib/projectname/home/' . $class_name);
    

    and then:

    $home = new homepage();
    

    concept of autoloader is simply to find class with a given name. it does not change class name on the fly.

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

Sidebar

Related Questions

I am just learning to use Services, and am sort of stuck. I have
Just learning the world of jquery, and all my googling gives examples like this:
I am just learning how to use classes in my projects. I have been
i'm just learning GWT MVP design pattern for weeks. now, i'd like to use
I'm just learning codeigniter, and I seem to have run into something that is
I'm just learning MVC and have a question that I'm sure is obvious to
I am just learning how to use ScriptingBridges. I made a method that slowly
I'm just learning how to use python and GAE and I've noticed that the
I'm just learning how to use MVP and I want to make sure that
I'm just learning how to use .net and mvc4 and I have a problem.

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.