Currently, I'm passing a command into a user-defined function in PHP. How do I have PHP execute this when I ask it to?
+3
A:
You'll want to either use eva
l or call_user_func
, depending on whether it's a set of expressions or simply a function call.
karim79
2009-07-04 22:50:28
+1
A:
If it's a shell command you want to execute you use backticks or shell_exec.
lemonad
2009-07-04 22:56:28
A:
As eval()
would be able to arbitrarily execute code on your server, maybe you can generate class files from your user application with any functions that a user might be authorized to call, then check for existence of a function using introspection in the newly generated class file first.
FilmJ
2009-07-04 23:49:07
+1
A:
If its a method in a class, maybe this will be useful :
// The method to call
$proposed_method = 'some_method_name';
// See if its available
if (is_callable(array($this,$proposed_method), FALSE))
{
// Call the method
return $this->$proposed_method();
}
Where $this in the is_callable refers to the current class.
ae
2009-07-05 12:04:35