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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:22:56+00:00 2026-06-02T22:22:56+00:00

I try function some_class($class) { require PATH.’test’.$class.’.php’; } function test_class($class) { require PATH.’some’.$class.’.php’; }

  • 0

I try

function some_class($class) {
        require PATH.'test'.$class.'.php';
    }



function test_class($class) {
        require PATH.'some'.$class.'.php';
    }

    spl_autoload_register("test_class");
    spl_autoload_register("some_class");


    $tst = new SomeClass();

SomeClass class locate in “PATH/some/SomeClass.php”, but spl_autoload_register call only “test_class” function and not call “some_class”. But if I change functions position, then it find new SomeClass.

  • 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-02T22:22:57+00:00Added an answer on June 2, 2026 at 10:22 pm

    Autoload functions are called in sequential order, the first registered function is called first, the second one is called after and so on, until one of them finds the class
    (unless $prepend is used). If none do, a fatal error is triggered.

    However, in your example, you are using require instead of include, so the first function will always fail with a fatal error if the file doesn’t exist, so the second one will never be called. Even if you replace it with include, if both files exist, only the first registered function will be invoked.

    It’s a good idea to use file_exists or include when using multiple autoload functions.

    You can also throw exceptions in your autoload functions, so that you can handle undefined classes gracefully instead of killing the script if a class is not found. Per example:

    function my_autoload($class) {
         $filename = "class.{$class}.php";
    
         if (!file_exists($filename))
             throw new Exception("$class not found");
    
         include_once $filename;
    }
    
    spl_autoload_register('my_autoload');
    
    try {
        $a = new Foo;
    } catch (Exception $e) {
        // Foo wasn't found
    }
    
    // continuing the script...
    

    Obviously it depends on your needs, as throwing an exception will halt the execution of subsequent autoload functions.

    Finally, it discouraged to use __autoload at all, spl_autoload_register providing a lot more flexibility that the former.

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

Sidebar

Related Questions

I try to have some inheritance with attributeBindings between two View. (function(exports) { Ember.MobileBaseView
I need to write a delegate function that can 'wrap' some while/try/catch code around
I'm refactoring some code and there are tons of functions with no try catch
I tried to do this: try{ (function($){ ... my plugin stuff })(jQuery); }catch(er){ alert(an
So I try such code: function showAlertWithCallback(w, h, name, body_text, functionToCallOnOk) { prepareWindow(); var
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I try to call a function which passed as function pointer with no argument,
I try to debug a javascript function called from Generate Thumbnails plugin in Wordpress.
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
i'll try and be as clear as possible. I'm working on some form validation

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.