hello,
I would like to create a new instance of a class, where the classname comes from a variable. Is it possible? I mean something like
$myObject = new {$classname}();
Would be quite thankful for any help.
Sebastian
Something like this, you mean?
class foo { var $gadget='Feng Shui'; function foo(){echo "FOO!\n";} } class bar { var $widget='Lebensraum'; function bar(){echo "BAAAA!\n";} } $whichclass = 'bar'; $thingy = new $whichclass(); var_dump($thingy);
Originally posted by Weedpacket Something like this, you mean? class foo { var $gadget='Feng Shui'; function foo(){echo "FOO!\n";} } class bar { var $widget='Lebensraum'; function bar(){echo "BAAAA!\n";} } $whichclass = 'bar'; $thingy = new $whichclass(); var_dump($thingy); [/B]
Originally posted by Weedpacket Something like this, you mean?
[/B]
Yes, you´re right. What I did wrong was that I used
$myObject = new get_class($this);
instead of
$_myClass = get_class($this); $myObject = new $_myClass;