In PHP, you can have named functions like this:
function foo()
{
return "bar";
}
And you can have Closures like this:
$foo = function() {
return "bar";
};
Closures are awesome and easy to create, but unfortunately a library I need to use really wants a named function. Is it possible to create a named function from closures dynamically? I.e. not defining all functions in code ahead of time, but more like a register_function($name, callable $closure)
.
I am aware of create_function
, but that one takes a PHP string as function body and just eval
s it, which is not what I'm looking for.