Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以使用PHP反射提取函数代码吗?_Php_Reflection - Fatal编程技术网

我可以使用PHP反射提取函数代码吗?

我可以使用PHP反射提取函数代码吗?,php,reflection,Php,Reflection,我正在使用PHP ReflectionClass尽可能多地提取有关类的信息。我还可以使用它从函数中获取返回值吗?或者,由于反射只分析对象接受的内容,所以这没有意义吗?如果函数具有定义良好的返回值,则可以从源代码中提取。想象一下这样的情景: return $this->isValid() ? $result : $this->createNullObject(); 这很难(或不可能)仅仅为了得到返回值而进行解析。您可以改为使用DocComments@return是该用途的常用标签 /

我正在使用PHP ReflectionClass尽可能多地提取有关类的信息。我还可以使用它从函数中获取返回值吗?或者,由于反射只分析对象接受的内容,所以这没有意义吗?

如果函数具有定义良好的返回值,则可以从源代码中提取。想象一下这样的情景:

return $this->isValid() ? $result : $this->createNullObject();
这很难(或不可能)仅仅为了得到返回值而进行解析。您可以改为使用DocComments@return是该用途的常用标签

/**
 * MyMethod
 *
 * @return int
 */

对ReflectionMethod对象调用getDocComment(),然后解析docComment。

有关可以使用的内部函数

$reflect = new ReflectionExtension('standard');
echo "<pre>" . $reflect . "</pre>"; 
$reflect=newreflectionextension('standard');
“回声”$反思。"";