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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:42:01+00:00 2026-06-12T20:42:01+00:00

I have this simple autoloading script, the only problem is that I do not

  • 0

I have this simple autoloading script, the only problem is that I do not know what variable my class1 is initialized. I var_dump the variable $class and it says

object(class1)[1]

But when I tried to $class->someMethod() variable class is undefined?

on my ClassLib Directory I have a

-class1.php and
-class2.php

My COde:

function init_load($class){ 
include 'ClassLib/'.$class.'.php'; 
}

function verify_fclass($class){
if(!file_exists('ClassLib/'.$class.'.php')){
    return FALSE;
}else{
    if(!class_exists($class)){
        return FALSE;
    }else{
        return TRUE;
    }
}

}

function init_classes($classes = array()){
foreach($classes as $class){
    if(verify_fclass($class) === FALSE){
        $test[$class.'NotExisting'] = $class;
    }else{
             $test = null;
             $class = new $class;
    }
}
var_dump($class); // what is on class
var_dump($test);  // what is on test
}

$class_array = array('NonExistingClass','class1');
spl_autoload_register('init_load');
init_classes($class_array);

$class->what();
  • 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-12T20:42:03+00:00Added an answer on June 12, 2026 at 8:42 pm

    You still have to define the class instance $class outside of the function scope.

    That means you should return $class in your init_classes function. The only problem I see here is that you want to be able to instantiate several classes at once so you might have to return an array of classes.

    You could try something like this:

    function init_classes($classes = array()){
        $error = array();
        $instances = array();
    
        foreach($classes as $class){
            if(verify_fclass($class) === FALSE){
                $error[$class.'NotExisting'] = $class;
            }
            else{
                $test = null;
                $instances[$class] = new $class;
            }
        }
        return array( 'error' => $error, 'instances' => $instances);
    }
    
    $class_array = array('NonExistingClass','class1');
    $class = $init['instances']['class1'];
    $class->what();
    

    But then again you could just instantiate the class directly without using an array and the init_classes method…

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

Sidebar

Related Questions

I have this simple script that I'm working on. I must admit, I'm totally
I have this simple redirection on my website and it does not rewrite my
I have this simple code, using Joda-time. Works fine, but I have a problem.
I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde
I have this simple query that works on all other database systems, but fails
I have this simple structure: 1 parent, and two different childs. public class Parent{}
I have this simple code in the first few lines of my script and
I have this simple code that plans to Scan a QR Code and return
i have this simple html: <div id="tree"> <div class="roi"> <ul> <li>text1</li> <li>text2</li> <li>text3 <ul>
i have this simple script: function paginateUsers(page){ get( _config_remote_host+'/users?page='+page,function(json){ json = JSON.parse(json); var _html

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.