FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to create an instance from a class name
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to create an instance from a class name [message #177820 is a reply to message #177814] Sun, 22 April 2012 14:15 Go to previous message
Leonardo Azpurua is currently offline  Leonardo Azpurua
Messages: 46
Registered: December 2010
Karma:
Member
"M. Strobel" <sorry_no_mail_here(at)nowhere(dot)dee> escribió en el mensaje
news:9vi0pdF23nU1(at)mid(dot)uni-berlin(dot)de...

> Just take the classname as variable in the new Operator:
>
> class clase1 {
> function buenos() {
> echo "Bon día!\n";
> }
> }
>
> class clase2 {
> function buenos() {
> echo "Buenos días!\n";
> }
> }
>
> foreach (array(1,2) as $v) {
> $cn = 'clase' . $v;
> $c = new $cn();
> $c->buenos();
> }
> #--------------------
> Bon día!
> Buenos días!

Too easy to be remembered!

Thanks, obrigado, gracias!

..
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session question
Next Topic: Open Source Software Links
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Feb 17 17:52:27 GMT 2025

Total time taken to generate the page: 0.04964 seconds