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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:16:52+00:00 2026-05-26T04:16:52+00:00

I have an spl_autoload being called but the problem is the second autoload does

  • 0

I have an spl_autoload being called but the problem is the second autoload does not execute and I can’t figure out why. With this code this code the script should die. I remove classes from folder array, the autoload will work. My code looks like this:

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors','On'); 
/*** nullify any existing autoloads ***/
spl_autoload_register(null, false);
/*** specify extensions that may be loaded ***/
spl_autoload_extensions('.php');

function dataLoader($class) {
    foreach (array(PV_CORE.DS.'data'.DS, PV_CORE.DS.'system'.DS, PV_CORE.DS.'cms'.DS, PV_CORE.DS.'util'.DS,PV_CORE.DS.'components'.DS, PV_CORE.DS.'template'.DS) as $folder){
        if (is_file($folder.$class.'.php')) {
            include_once $folder.$class.'.php';
        }
    }//end foreach
}

function testLoader($class) {
    die();
    $filename = $class. '.php';
    $file =PV_CORE.DS.'data'.DS.$filename;
    if (!file_exists($file)) {
        return false;
    }
    require_once $file;
}

spl_autoload_register('dataLoader');
spl_autoload_register('testLoader');
  • 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-05-26T04:16:53+00:00Added an answer on May 26, 2026 at 4:16 am

    Your code works but probably a misunderstanding.

    Your functions are registered:

    print_r( spl_autoload_functions() );
    

    returns:

    Array
    (
        [0] => dataLoader
        [1] => testLoader
    )
    

    and if you initialize a class

    $class_obj = new ClassName();
    

    dataLoader will try to load the file:

    $folder.ClassName.php
    

    Your script will only load the second or any other registered function if he can’t find the class in the first place.

    So if you remove your $class in the function dataLoader __autoload wont find the class anymore in the first registered function so he will try to look up for it in the second registered function and so on.

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

Sidebar

Related Questions

This simple example won't work, gives me: Fatal error: spl_autoload() [function.spl-autoload]: Class GmailServer could
Can anyone help me with this? I have this function in a singleton class.
Would the second autoload method I have below be better performance? <?php // regular
I have just started experiencing this problem: The site is fine until I add
Why does this autoload class duplicate the db connection? class autoloader { private $directory_name;
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have to install big CMS on my localhost, but it requires mcrypt, and
How does one paginate a large listing of files within a folder? I can't
I have got a class which is called BaseCore which just runs all the

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.