How to new a Object via class name String?

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

 



Hi  , I'm a  freshman in PHP, can anyone give me any  advices?

I defied some simple classes, like "User", "Item"...

in a general way ,
 $obj = new User(); 

specially, I need  to assign a Object via a class name .

Now , my code :
 switch ($className)
{
 case "User":
    return new User();
    break ;
 case "Item":
    return new Item();
    break ;
 default:
    break ;
}

I think that It's not a clever  job. How to do it skillfully?

Thank you for any advice.

-- 
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