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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:38:32+00:00 2026-06-09T05:38:32+00:00

I use this simple autoloader code: function __autoload( $class_name ) { include ‘class.’ .

  • 0

I use this simple autoloader code:

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

and I make this call new SDB();

SDB actually inherits from SDBOne which I never include…yet the auto-loader loads it.

This means it knows to load modules nested / included in other modules.

So from the looks of it I never need to require or include anything if I use the auto-loader.

However, if I use a stand alone module where there is no auto-loader, I then need to include the class it inherits from.

Should I use

require,

require_once,

include,

include_once.

I would guess to go with require_once because I want an error not a warning…plus when I use the code with the autoloader I don’t want it loaded twice.

Basically I have 2 types of use for SDB : one with the autoloader present and one with out.

Reference

http://php.net/manual/en/language.oop5.autoload.php

  • 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-09T05:38:34+00:00Added an answer on June 9, 2026 at 5:38 am

    You are correct, require_once would be the correct way to include a parent class or dependent class in one file. That way if its included multiple times, the require_once prevents errors that would arise from redeclaring a class.

    The autoloader is autoloading SDBOne automatically because it needs that class defined before it can extend SDB from it. The same thing is happening to autoload the parent class on demand as happens when you try to load the inherited class.

    Also, you should consider switching to spl_autoload_register so that your code will work well with other code that may use an autoloader. The SPL autoloader supports multiple autoloaders and creates a stack in the order they are registered. This way if the first autoloader doesn’t satisfy the requirement, it keeps trying subsequently registered autoloaders until the class is loaded or cannot be found.

    Another note on preventing errors, you may want to change your autoload function as follows:

    function __autoload( $class_name ) { 
        $file = 'class.' . $class_name . '.php';
        if (file_exists($file)) {
            include $file;
        }
    }
    

    Because if the class being autoloaded doesn’t exist, you will get errors about including a non-existent file. This is especially important when using spl_autoload_register; you don’t want your autoloader to emit unnecessary warnings about missing files if another autoloader will be ultimately responsible for loading the class in question.

    Hope that helps.

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

Sidebar

Related Questions

im tryin to use this simple function: http://code.google.com/p/canvasimagegradient/ i have to create a linear
i have this simple php code and want to use this code in a
In my open-source plain C code I use this simple structure to read and
Am I missing something? I use this simple code <a name=fb_share type=button href=https://www.facebook.com/sharer.php?u=123.abc.comt=TEst>share on
I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically
I use this simple Javascript code to retrieve text that was selected on a
Hi I use this simple jquery : $(document).ready(function(e) { $(#langs_current).click(function(){ $(#langz).toggle(350); }); }); Currently
I am trying to use this simple function from this page: http://www.haskell.org/haskellwiki/99_questions/Solutions/2 But when
This simple example won't work, gives me: Fatal error: spl_autoload() [function.spl-autoload]: Class GmailServer could
In order to add events we could use this simple first solution : function

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.