Using variable content to name a class

From: Date: Mon, 05 Jun 2006 07:33:52 +0000
Subject: Using variable content to name a class
Groups: php.general 
Request: Send a blank email to php-general+get-237395@lists.php.net to get a copy of this message
PHP list, I suspect this is a rather basic concept, but I could not find the specifics in the online manual. I have a set of classes, and the name of each class is stored in a column in a table in my MySQL database. When I want to create an object from one of my classes, I also query the database to get a bunch of data the object needs, along with its name. So what I end up with is a variable with the name of the class that I want to use stored as a string. This means that I want to create an object by naming which class with the contents of a variable: $className = "nameFromDatabase"; $object = new $className(); Is this possible? I hope I've asked my question clearly. Thank you for any advice. -- Dave M G

« previous php.general (#237395) next »