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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:56+00:00 2026-06-12T09:13:56+00:00

I am new to php and I want to use php5’s __autoload functionality in

  • 0

I am new to php and I want to use php5’s __autoload functionality in my code. I wrote below code in my index.php but I don’t understand how and when I should call __autoload function.

function __autoload($class) {
    if (file_exists($class . '.php')) {
        include($class . '.php');
    } else {
        throw new Exception('Unable to load class named $class');
    }
}

I have seen this thread also but I do not have such autoloader class in my application. Do every application need a separate class in order to use autoloading? If not can I have a single function like above and complete it’s task?
Can anyone explain how to call above __autoload function inside my php code?

  • 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-12T09:13:57+00:00Added an answer on June 12, 2026 at 9:13 am

    You don’t call __autoload() yourself, PHP does when it is trying to find the implementation of a class.

    For example…

    function __autoload($className) {
         include $className . '.php';
    }
    
    $customClass = new CustomClass;
    

    …this will call __autoload(), passing CustomClass as an argument. This (stupid for example’s sake) __autoload() implementation will then attempt to include a file by tacking the php extension on the end.

    As an aside, you should use spl_autoload_register() instead. You can then have multiple implementations, useful when using multiple libraries with auto loaders.

    …using __autoload() is discouraged and may be deprecated or removed in the future.

    Source.

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

Sidebar

Related Questions

I'm new to PHP and I want this code <option value= disabled=disabled>-------------</option> to be
I'm new to PHP programming and have poor knowledge about it, but I want
I'm pretty proficient in PHP, but want to try something new. I'm also know
I want to use the new PHP 5 > input filtering to sanitize and
I use some code from the PHP manual to make an exception test, but
I'm new to PHP but was wondering how this can be done. I want
im new in PHP and I want to know about PHP Zend Framework. What
I am new to php. I want to have a form such as this:
I'm so new in php. I want to ask for decbin function in PHP
I am new with cron job in php,basically i want to send email to

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.