This is a discussion on Calling functions which names are inside a variable within the PHP General forums, part of the PHP Programming Forums category; On Sat, 2007-08-25 at 23:46 -0600, Robert Keizer wrote: > I am currently working on a module ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Sat, 2007-08-25 at 23:46 -0600, Robert Keizer wrote:
> I am currently working on a module testing class, I can't seem to find the > correct syntax. Here is an example of the problem: > > function foo( $var ){ > include $var.'.php'; > return $var(); // <!------- problem > }; > > foo("somefunction"); > > In other words I am looking for a way to call a function by the value of a > variable. I get a Call to undefined method error, > any help would be great.. You are calling the function correctly when using a variable. Namely: $var(); Check that the include file you want included is actually being included. My guess is that it is not, or the function you expect to be defined in it is not actually defined there. Cheers, Rob. -- .................................................. .......... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! .................................................. .......... |
|
|||
|
I am currently working on a module testing class, I can't seem to find the
correct syntax. Here is an example of the problem: function foo( $var ){ include $var.'.php'; return $var(); // <!------- problem }; foo("somefunction"); In other words I am looking for a way to call a function by the value of a variable. I get a Call to undefined method error, any help would be great.. -- nuclearsanta@gmail.com |
|
|||
|
Thats great thanks, but it doesn't solve my problem completly, im trying to
use $output = $var(); .. which gives me an error. The $var(); works though, so thanks for that. Robert Keizer ""Robert Keizer"" <nuclearsanta@gmail.com> wrote in message news:op.txnjmzww9011uo@lenovo-b0c37194... >I am currently working on a module testing class, I can't seem to find the >correct syntax. Here is an example of the problem: > > function foo( $var ){ > include $var.'.php'; > return $var(); // <!------- problem > }; > > foo("somefunction"); > > In other words I am looking for a way to call a function by the value of a > variable. I get a Call to undefined method error, > any help would be great.. > > -- > nuclearsanta@gmail.com |
|
|||
|
I tested this functionality.
This is working fine. foo.php <? function foo( $var ){ include $var.'.php'; return $var(); }; foo("somefunction"); ?> somefunction.php <? function somefunction(){ echo "hello"; } ?> Out put is hello. You make sure that your both files are in same folder and make sure that $var.'.php' is exist with $var function. Warm Regards, Sanjeev http://www.sanchanworld.com/ http://webdirectory.sanchanworld.com - Submit your website URL http://webhosting.sanchanworld.com - Choose your best web hosting plan -----Original Message----- From: Robert Keizer [mailto:nuclearsanta@gmail.com] Sent: Sunday, August 26, 2007 11:16 AM To: php-general@lists.php.net Subject: [php] Calling functions which names are inside a variable I am currently working on a module testing class, I can't seem to find the correct syntax. Here is an example of the problem: function foo( $var ){ include $var.'.php'; return $var(); // <!------- problem }; foo("somefunction"); In other words I am looking for a way to call a function by the value of a variable. I get a Call to undefined method error, any help would be great.. -- nuclearsanta@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|||
|
On Sun, August 26, 2007 12:46 am, Robert Keizer wrote:
> I am currently working on a module testing class, I can't seem to find > the > correct syntax. Here is an example of the problem: > > function foo( $var ){ > include $var.'.php'; > return $var(); // <!------- problem Try this: return ($var()); Not sure it's the answer, but suspect it might be. And 'somefunction' *IS* defined, right?... > }; -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |