Page 1 of 1

Executing a function when it's a string

Posted: Tue May 23, 2006 7:26 pm
by Sphenn
Hi,

I'm currently using a system that creates gathers a function name and required function arguments to be executed on the system. However, it outputs the resulting code as a string. For example, I can have something like:

Code: Select all

echo "$this->method($this->arguments)"; // Outputs some_func('foo', TRUE)
My problem is that I want to actually call some_func (which is a function in an included file.

I've tried using commands such as exec, shell_exec, and others, but they're not quite what I'm looking for. Also, simply writing:

Code: Select all

$this->method($this->arguments);
does not work.

If anyone has any comments, they would be appreciated.

Thank you,

Sphenn

Posted: Tue May 23, 2006 7:40 pm
by Ambush Commander
eval()

Careful about the security implications though.

Posted: Tue May 23, 2006 7:42 pm
by Sphenn
Ahh.... that's the function I was looking for. Maybe that's why exec sprang to mind.

Thanks so much

Sphenn

Posted: Wed May 24, 2006 1:55 am
by xpgeek
Try it.

Code: Select all

function my_callback_function() {
   echo 'hello world!';
}
call_user_func('my_callback_function');

Posted: Wed May 24, 2006 3:51 am
by Christopher

Code: Select all

$func = $this->method;
$func($this->arguments);