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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:54:56+00:00 2026-06-06T04:54:56+00:00

class Manage { spl_autoload_register(function($class) { include $class . ‘.class.php’; }); } Say I have

  • 0
class Manage
{

spl_autoload_register(function($class) {
    include $class . '.class.php';
});
}

Say I have some code like the above. I chose to use the anonymous function method of loading classes, but how is this used? How exactly does it determine which '$class' to load?

  • 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-06T04:54:57+00:00Added an answer on June 6, 2026 at 4:54 am

    You can’t put the code there. You should add the SPL register after your class. If you wanted to register a function inside the Manage class you could do:

    class Manage {
        public static function autoload($class) {
            include $class . '.class.php';
        }
    }
    
    spl_autoload_register(array('Manage', 'autoload'));
    

    However, as you demonstrated you can use an anonymous function. You don’t even need a class, so you can just do:

    spl_autoload_register(function($class) {
        include $class . '.class.php';
    });
    

    Either way, the function you specify is added to a pool of functions that are responsible for autoloading. Your function is appended to this list (so if there were any in the list already, yours will be last). With this, when you do something like this:

    UnloadedClass::someFunc('stuff');
    

    PHP will realize that UnloadedClass hasn’t been declared yet. It will then iterate through the SPL autoload function list. It will call each function with one argument: 'UnloadedClass'. Then after each function is called, it checks if the class exists yet. If it doesn’t it continues until it reaches the end of the list. If the class is never loaded, you will get a fatal error telling you that the class doesn’t exist.

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

Sidebar

Related Questions

I'd like to provide a class to manage creation and subsequent deletion of a
I have created a class that will manage connection and commands, I named it
I'm looking at a simple class I have to manage critical sections and locks,
I have a managed class library (say mylib.dll) and a 3rd party managed app
I have an sqlConnection manager class like so: public class SQLConn { public string
I'm developing a class to manage the operations on a Mysql database. I have
I am using PHP S3.PHP class to manage files on Amazon S3. I use
Lets say, for example, that I have a class that requires the use of
I try to create a class to manage some part of my app but
i'd like to use a class to manage a certain cookie, but not directly

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.