instantiating class question..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codemonkey46
Forum Newbie
Posts: 2
Joined: Thu Aug 16, 2007 6:23 pm

instantiating class question..

Post 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).
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Simpler than you think

Code: Select all

$obj = &new $className;
;)
codemonkey46
Forum Newbie
Posts: 2
Joined: Thu Aug 16, 2007 6:23 pm

Post by codemonkey46 »

Great! Thanks much stereofrog.

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