Dynamically creating objects using variable for class name
Posted: Wed Jan 22, 2003 10:34 am
I'm eager to know if the subj is possible.
I got such situation like:
1) Several classes, more coming, they serve similiar purposes but each have specific functionality
2) I'm getting list of objects needed from table
3) I need to create the class object, class name is stored in variable (got from DB).
What I've done - got the class name, included corresponding file (no problem with that), tried such construction like:
/************************************/
$obj = new $className;
/************************************/
and got the error:
Fatal error: Cannot instantiate non-existent class
However I've included the file containing the class
Would be very nice to see any solution for this problem.
I got such situation like:
1) Several classes, more coming, they serve similiar purposes but each have specific functionality
2) I'm getting list of objects needed from table
3) I need to create the class object, class name is stored in variable (got from DB).
What I've done - got the class name, included corresponding file (no problem with that), tried such construction like:
/************************************/
$obj = new $className;
/************************************/
and got the error:
Fatal error: Cannot instantiate non-existent class
However I've included the file containing the class
Would be very nice to see any solution for this problem.