Page 1 of 1

instantiating class question..

Posted: Thu Aug 16, 2007 6:28 pm
by codemonkey46
So I'm basically trying to create a CRUD class, that, when passed the class name, can figure out the basic CRUD operations on it's own using get_class_vars as well as some other means. However, I cannot figure out how to instantiate a class if you have a variable that holds the class name. I know I could use the eval function, but I'm worried about performance if I do that. Was hoping there was something along the lines of $data = new class($dataClass); that was fairly efficient.

I'm using the latest version of php 4 (yeah....don't ask...want five, but due to circumstances out of my control it ain't gonna happen).

Posted: Thu Aug 16, 2007 7:05 pm
by stereofrog
Simpler than you think

Code: Select all

$obj = &new $className;
;)

Posted: Mon Aug 20, 2007 6:03 pm
by codemonkey46
Great! Thanks much stereofrog.

Yeah, didn't think it would be that easy, glad it is :D