PHP反射获取当前函数的内容
<?php $test = function () { echo 'hello world'; }; function closure_dump($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)); } closure_dump($test);
- 作者:踏雪无痕
- 出处:http://www.cnblogs.com/chenpingzhao/
- 本文版权归作者和博客园共有,如需转载,请联系 pingzhao1990#163.com