public static function getFunctionBody(\ReflectionFunctionAbstract $function) { $source = file($function->getFileName()); $start = $function->getStartLine() - 1; $end = $function->getEndLine(); $body = implode('', array_slice($source, $start, $end - $start)); $open = strpos($body, '{'); $close = strrpos($body, '}'); return trim(substr($body, $open + 1, (strlen($body) - $close) * -1)); }
public function testFunctionBody() { $actual = ReflectionUtils::getFunctionBody(new \ReflectionFunction('wurst')); $expected = 'return \'wurst\';'; $this->assertEquals($expected, $actual); $actual = ReflectionUtils::getFunctionBody(new \ReflectionFunction('inline')); $expected = 'return \'x\';'; $this->assertEquals($expected, $actual); }