Page 1 of 1

Instantiate by var name

Posted: Sun Jun 19, 2005 12:53 pm
by Todd_Z
If I have a string, for example $str = "Class"; How can I cause $obj to be the result of new Class()?

Posted: Sun Jun 19, 2005 12:58 pm
by Todd_Z
I love how I sit here thinking about how to solve a problem for 10 minutes, then immediately after posting, the answers pops into my Head. This is another one of those moments where you just have to say "I love you, php"

Code: Select all

$class = "ClassName";
$obj = new $class( $arg[0], $arg[1], ... );

Posted: Sun Jun 19, 2005 1:13 pm
by John Cartwright
Glad we could help.