PHP 反射获取函数体
PHP 通过反射获取函数体
<?php function hello() { var_dump("hello"); } function get_function_define($closure) { try { $func = new ReflectionFunction($closure); } catch (ReflectionException $e) { echo $e->getMessage(); return; } $start = $func->getStartLine() - 1; $end = $func->getEndLine() - 1; $filename = $func->getFileName(); echo implode("", array_slice(file($filename), $start, $end - $start + 1)); } get_function_define("hello");
这样就能拿到函数体了。