Re: Dynamic Function Call
| From: | Tom Rogers | Date: | Mon, 07 Jun 2004 13:59:09 +0000 |
| Subject: | Re: Dynamic Function Call | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187789@lists.php.net to get a copy of this message | ||
Hi,
Monday, June 7, 2004, 11:47:00 AM, you wrote:
> Hello everyone!
> I'm trying to call a class method dynamically, but keep getting a SYNTAX
> ERROR. Can anyone shed some light on this? Is this impossible?
> ==The Code
> function &modCall($_class){
> $this->LoadClass($_class); //LoadClass includes the class file, but
> //does not initialize it.
> //if the class has the method, then call it.
> if(in_array('sayHello',get_class_methods($_class)){
> $_class::sayHello();
> // this line reports a syntax error with $_class::sayHello()
> // but (assuming the value of $_class was 'myClass')
> // myClass::sayHello() works!
> }
> //I've also tried the following:
> // ${_class)::sayHello();
> // {$_class}::sayHello();
> // $_class.'::sayHello()';
> }
> Any suggestions!
> =P e p i e D e s i g n s
> www.pepiedesigns.com
> Providing Solutions That Increase Productivity
> Web Developement. Database. Hosting. Multimedia.
You could try eval()
--
regards,
Tom