Skip to content

Instantly share code, notes, and snippets.

@engine-andre
Created June 13, 2013 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engine-andre/5772769 to your computer and use it in GitHub Desktop.
Save engine-andre/5772769 to your computer and use it in GitHub Desktop.
get code string from an function
$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