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);
原文地址:https://www.cnblogs.com/chenpingzhao/p/4534611.html