Instantiate by var name
Moderator: General Moderators
Instantiate by var name
If I have a string, for example $str = "Class"; How can I cause $obj to be the result of new Class()?
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], ... );- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: