RE: [PHP] Calling functions which names are inside a variable
| From: | Sanjeev N | Date: | Sun, 26 Aug 2007 06:39:36 +0000 |
| Subject: | RE: [PHP] Calling functions which names are inside a variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261286@lists.php.net to get a copy of this message | ||
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