Re: Using variable content to name a class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux