kartul Posted June 14, 2011 Share Posted June 14, 2011 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 https://forums.phpfreaks.com/topic/239378-creating-new-class-by-variable-not-working/ Share on other sites More sharing options...
mikesta707 Posted June 14, 2011 Share Posted June 14, 2011 Have you verified that the path you are using to include the class definition is correct? Link to comment https://forums.phpfreaks.com/topic/239378-creating-new-class-by-variable-not-working/#findComment-1229793 Share on other sites More sharing options...
kartul Posted June 14, 2011 Author Share Posted June 14, 2011 Yes because when I replace $class with test, it works. // edit. And I mean in the line $this->loaded_classes[$class] = new test(); Link to comment https://forums.phpfreaks.com/topic/239378-creating-new-class-by-variable-not-working/#findComment-1229794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.