Created
June 13, 2013 10:33
-
-
Save engine-andre/5772769 to your computer and use it in GitHub Desktop.
get code string from an function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$func = new ReflectionFunction('myfunction'); | |
$filename = $func->getFileName(); | |
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block | |
$end_line = $func->getEndLine(); | |
$length = $end_line - $start_line; | |
$source = file($filename); | |
$body = implode("", array_slice($source, $start_line, $length)); | |
print_r($body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment