Can I use PHP reflection to extract function code?
I am using PHP ReflectionClass to extract as开发者_StackOverflow中文版 much information about a class as possible. Can I also use this to get return values from functions? Or does that not make sense since reflection only profiles what an object accepts?
You can not rely, if a function has a well defined return value you can simply extract from the source code. Imagine something like this:
return $this->isValid() ? $result : $this->createNullObject();
Thats hard (/impossible) to parse just to get the return value. You can use DocComments instead. @return is the usual tag for that use
/**
* MyMethod
*
* @return int
*/
Call getDocComment() on a ReflectionMethod-object and then parse the docComment.
for internal functions you could use
$reflect = new ReflectionExtension('standard');
echo "<pre>" . $reflect . "</pre>";
精彩评论