tags:

views:

29

answers:

1

I have a variable called $theclass and it's a string "Home_class". How can I define a class out of that string? The reason I need to do this is that the variable will change and I want to be able to declare the class that the variable is equal to. Is this possible?

Thanks for any help.

+4  A: 

Use the new keyword.

$theclass = 'My_class';
$x = new $theclass(); // $x is now an instance of My_class
meagar
that works perfecly, I have to wait 11 minutes to mark answer as correct though. Thanks.
Raphael Caixeta