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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:03+00:00 2026-05-25T00:03:03+00:00

I am using __autoload in my script to include classes as needed. My script

  • 0

I am using __autoload in my script to include classes as needed. My script uses cues in the class name to find the file containing it. If it ends in model it is in the model directory, controllers are in the controller directory, etc. I am starting to implement interfaces, and so need to adjust my autoloader.

Ideally, when an object is created the autoloader would determine the file-name of the object, where it is stored, and include the file. Then it would interrogate that class for what interfaces it implements, and then include those files automatically.

Something like

function __autoload($classname){
    echo $classname;
    include ("classes/$classname.php");
    $interfaces = class_implements($classname,FALSE);
    foreach($interfaces as $name){
        if(!class_exists($name,FALSE)){
        include("interfaces/".$name."inter.php");
        }
    }
}

Except when I do that I get the error

Cannot redeclare __autoload() (previously declared in
W:\xampp\htdocs\test\auto.php:5) in W:\xampp\htdocs\test\auto.php on
line 11

is it not possible to do this in the __autoload()? Should I just continue relying on naming conventions to differentiate between types of objects and where they are stored?

  • 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-25T00:03:04+00:00Added an answer on May 25, 2026 at 12:03 am

    You cannot define a class, before the implemented interfaces are defined and additional any unknown interface will trigger the autoload function too. This means in line 3 when including the class it will trigger the autoload function again with the interfaces as $classname. Now when returning from the second __autoload()-call it will try to include the interfaces once more, which will fail because of “already defined”.

    Additional: Using __autoload() is deprecated against using spl_autoload_register()

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

Sidebar

Related Questions

I'm using APC for storing a map of class names to class file paths.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Let's say were using custom extensions of the Exception class to handle custom exceptions,
I am using __autoload() which simply looks like this: function __autoload($class_name) { require_once($class_name .
I have an ajax script executed using jquery when an input text field is
I am trying to generate a migration script using Doctrine with Zend Framework. I
I am using Rails 2.3.5, and in it, to autoload classes from lib folder,
I am using Ext.data.Store to call a PHP script which returns a JSON response
I'm using PHP Doctrine and i've setup autoloading: spl_autoload_register(array('Doctrine', 'autoload')); spl_autoload_register(array('Doctrine', 'modelsAutoload')); I can
I'm using videoDisplay MXML component for my Flex app. I would like to autoload

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.