Re: How to call a function from $classname
| From: | Jochem Maas | Date: | Tue, 15 Mar 2005 16:06:44 +0000 |
| Subject: | Re: How to call a function from $classname | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210811@lists.php.net to get a copy of this message | ||
André Pletschette wrote:
Hi, What do I have to do to call a function from $classname? Like: $classname->test( );<?php // does $classname contain a name of a class? e.g: class Test { function doIt() { echo "done it!\n"; } } $className = "Test"; $t = new $className; $t->doIt(); // also look at the functions // call_user_func() and call_user_func_array(), // e.g: call_user_func( array($className,"doIt") ); ?> BTW: I'm only using double-quotes when its really needed because it makes testing the code in a linux shell 100 times easier (when compared to using single-quotes). AGAIN BTW: nobody understood your question so far because '$classname->test();' is valid php syntax! (it just assumes that $classname 'is' an object, not a string) happy now? ;-)
Thankyou, André