I'm trying to solve a problem :
function f($callable_function){
print_r($callable_function);// doesn't work at all, of course
}
f(function(){echo "hello World"});
I get the Closure Object
element with my print_r function. Is there a way to get :
//OUTPUT RESULT
echo "hello World";
EDIT
The purpose of this is to get the function declaration inside a String (for database later). The f function can be used by any developer so the idea is to make this as simple as possible, that means I don't want the developer to declare his function inside of a String.
Never closed this question but I have the answer since 2014 :
$reflFunc = new ReflectionFunction($callable);
$filename = $reflFunc->getFileName());
$startline = $reflFunc->getStartLine();
$endline = $reflFunc->getEndLine();
And using preg_match
, I can extract what I need. (as suggested by
the first answer)