Note: I don’t think this question has much to do with PHP’s eval.
In Tcl, eval takes a list, using the first item as the function (proc) name, and the rest of the items as arguments, e.g.
eval [list foobar arg1 arg2 arg3]
is equivalent to
foobar arg1 arg2 arg3
In PHP, both call_user_func and call_user_func_array require at least two parameters: (1) the function name, and (2) either the arguments or an array of the arguments, respectively.
Is there a similar function in PHP that takes only one parameter?
I wrote my own, as shown below, but I’d prefer a native method.
function call_user_array(array $a) {
return call_user_func_array(array_shift($a), $a);
}
Thanks in advance for any hints.
P.S. Not sure if “lambda” has anything to do with this but the word comes to mind for some reason: would someone more knowledgeable please remove the tag if it’s not actually relevant, as well as this note? Thanks again!
No, there is nothing built-in to do that. Since it can be implemented in one line (just like you did it) there’s also not much reason to consider including one.