// get_function_source($function_name) function get_function_source($function_name) { $f = new ReflectionFunction($function_name); $str = join("\n", array_slice(explode("\n", file_get_contents($f->getFileName())), $f->getStartLine()-1, $f->getEndLine() + 1 - $f->getStartLine())); // try to strip leading and trailing whitespace and comments, not guaranteed to work perfectly obviously $str = substr($str, strpos($str, 'function')); $str = substr($str, 0, strrpos($str, '}')+1); return $str; }