Re: Using variable content to name a class

From: Date: Mon, 05 Jun 2006 07:58:53 +0000
Subject: Re: Using variable content to name a class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237396@lists.php.net to get a copy of this message
Dave M G wrote:
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?
If in doubt, test it out ;) Yes, it will work. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#237396) next »