Jump to content

Creating new class by variable not working


kartul

Recommended Posts

Hey all :)

 

Creating new class by variable should work, atleast in php manual says so but why it isn't working here? Using php 5.3.7.

Error it says is can't find class called 'test'. It is there and if I replace $class with test the it works. And $class is equal to test.

 

function load_class($path, $class)
	{
		$class = strtolower($class);
		if( isset( $this->loaded_classes[$class] ) )
		{
			return $this->loaded_classes[$class];
		}
		else
		{

			#include $path . 'test.php';
			#include './' . $class . '.php';
			#debug_backtrace($class);
			#$s = new $class;
			include $path . $class . '.php';
			#eval('self::$loaded_classes['.$class.'] = new '.strtolower($class).'();');
			$this->loaded_classes[$class] = new $class();
			echo 'ok';
			return $this->loaded_classes[$class];
		}
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.